2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
30 #include "GameObject.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
39 #include "GridNotifiersImpl.h"
42 #include "PointMovementGenerator.h"
43 #include "TargetedMovementGenerator.h"
44 #include "SkillDiscovery.h"
45 #include "SkillExtraItems.h"
46 #include "SystemConfig.h"
47 #include "Config/ConfigEnv.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
54 bool ChatHandler::HandleReloadCommand(const char* arg
)
56 // this is error catcher for wrong table name in .reload commands
57 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg
);
58 SetSentErrorMessage(true);
62 bool ChatHandler::HandleReloadAllCommand(const char*)
64 HandleReloadAreaTriggerTeleportCommand("");
65 HandleReloadSkillFishingBaseLevelCommand("");
67 HandleReloadAllAreaCommand("");
68 HandleReloadAllLootCommand("");
69 HandleReloadAllNpcCommand("");
70 HandleReloadAllQuestCommand("");
71 HandleReloadAllSpellCommand("");
72 HandleReloadAllItemCommand("");
73 HandleReloadAllLocalesCommand("");
75 HandleReloadCommandCommand("");
76 HandleReloadReservedNameCommand("");
77 HandleReloadMangosStringCommand("");
78 HandleReloadGameTeleCommand("");
82 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
84 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
85 HandleReloadAreaTriggerTeleportCommand("");
86 HandleReloadAreaTriggerTavernCommand("");
87 HandleReloadGameGraveyardZoneCommand("");
91 bool ChatHandler::HandleReloadAllLootCommand(const char*)
93 sLog
.outString( "Re-Loading Loot Tables..." );
95 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
99 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
101 HandleReloadNpcGossipCommand("a");
102 HandleReloadNpcOptionCommand("a");
103 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog
.outString( "Re-Loading Quests Relations..." );
114 objmgr
.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld
.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
128 sLog
.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
138 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
140 HandleReloadSkillDiscoveryTemplateCommand("a");
141 HandleReloadSkillExtraItemTemplateCommand("a");
142 HandleReloadSpellAffectCommand("a");
143 HandleReloadSpellChainCommand("a");
144 HandleReloadSpellElixirCommand("a");
145 HandleReloadSpellLearnSpellCommand("a");
146 HandleReloadSpellProcEventCommand("a");
147 HandleReloadSpellScriptTargetCommand("a");
148 HandleReloadSpellTargetPositionCommand("a");
149 HandleReloadSpellThreatsCommand("a");
150 HandleReloadSpellPetAurasCommand("a");
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
161 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
163 HandleReloadLocalesCreatureCommand("a");
164 HandleReloadLocalesGameobjectCommand("a");
165 HandleReloadLocalesItemCommand("a");
166 HandleReloadLocalesNpcTextCommand("a");
167 HandleReloadLocalesPageTextCommand("a");
168 HandleReloadLocalesQuestCommand("a");
172 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
174 sLog
.outString( "Re-Loading config settings..." );
175 sWorld
.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog
.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr
.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog
.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr
.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table
= true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
203 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
205 sLog
.outString( "Loading Quests Relations... (`creature_questrelation`)" );
206 objmgr
.LoadCreatureQuestRelations();
207 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
211 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
213 sLog
.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
214 objmgr
.LoadCreatureInvolvedRelations();
215 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
219 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
221 sLog
.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
222 objmgr
.LoadGameobjectQuestRelations();
223 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
227 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
229 sLog
.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
230 objmgr
.LoadGameobjectInvolvedRelations();
231 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
235 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
237 sLog
.outString( "Re-Loading Quest Area Triggers..." );
238 objmgr
.LoadQuestAreaTriggers();
239 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog
.outString( "Re-Loading Quest Templates..." );
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
251 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
253 sLog
.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
254 LoadLootTemplates_Creature();
255 LootTemplates_Creature
.CheckLootRefs();
256 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
260 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
262 sLog
.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
263 LoadLootTemplates_Disenchant();
264 LootTemplates_Disenchant
.CheckLootRefs();
265 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
269 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
271 sLog
.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
272 LoadLootTemplates_Fishing();
273 LootTemplates_Fishing
.CheckLootRefs();
274 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
278 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
280 sLog
.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
281 LoadLootTemplates_Gameobject();
282 LootTemplates_Gameobject
.CheckLootRefs();
283 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
287 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
289 sLog
.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
290 LoadLootTemplates_Item();
291 LootTemplates_Item
.CheckLootRefs();
292 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
296 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
298 sLog
.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
299 LoadLootTemplates_Pickpocketing();
300 LootTemplates_Pickpocketing
.CheckLootRefs();
301 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
305 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
307 sLog
.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
308 LoadLootTemplates_Prospecting();
309 LootTemplates_Prospecting
.CheckLootRefs();
310 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
314 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
316 sLog
.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
317 LoadLootTemplates_QuestMail();
318 LootTemplates_QuestMail
.CheckLootRefs();
319 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
323 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
325 sLog
.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
326 LoadLootTemplates_Reference();
327 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
331 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
333 sLog
.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
334 LoadLootTemplates_Skinning();
335 LootTemplates_Skinning
.CheckLootRefs();
336 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog
.outString( "Re-Loading mangos_string Table!" );
343 objmgr
.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
348 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
350 sLog
.outString( "Re-Loading `npc_option` Table!" );
351 objmgr
.LoadNpcOptions();
352 SendGlobalSysMessage("DB table `npc_option` reloaded.");
356 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
358 sLog
.outString( "Re-Loading `npc_gossip` Table!" );
359 objmgr
.LoadNpcTextId();
360 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
364 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
366 sLog
.outString( "Re-Loading `npc_trainer` Table!" );
367 objmgr
.LoadTrainerSpell();
368 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
372 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
374 sLog
.outString( "Re-Loading `npc_vendor` Table!" );
375 objmgr
.LoadVendors();
376 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
380 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
382 sLog
.outString( "Loading ReservedNames... (`reserved_name`)" );
383 objmgr
.LoadReservedPlayersNames();
384 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
388 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
390 sLog
.outString( "Re-Loading Skill Discovery Table..." );
391 LoadSkillDiscoveryTable();
392 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
396 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
398 sLog
.outString( "Re-Loading Skill Extra Item Table..." );
399 LoadSkillExtraItemTable();
400 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
404 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
406 sLog
.outString( "Re-Loading Skill Fishing base level requirements..." );
407 objmgr
.LoadFishingBaseSkillLevel();
408 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
412 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
414 sLog
.outString( "Re-Loading SpellAffect definitions..." );
415 spellmgr
.LoadSpellAffects();
416 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
420 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
422 sLog
.outString( "Re-Loading Spell Chain Data... " );
423 spellmgr
.LoadSpellChains();
424 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
428 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
430 sLog
.outString( "Re-Loading Spell Elixir types..." );
431 spellmgr
.LoadSpellElixirs();
432 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
436 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
438 sLog
.outString( "Re-Loading Spell Learn Spells..." );
439 spellmgr
.LoadSpellLearnSpells();
440 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
444 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
446 sLog
.outString( "Re-Loading Spell Proc Event conditions..." );
447 spellmgr
.LoadSpellProcEvents();
448 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
452 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
454 sLog
.outString( "Re-Loading SpellsScriptTarget..." );
455 spellmgr
.LoadSpellScriptTarget();
456 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
460 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
462 sLog
.outString( "Re-Loading Spell target coordinates..." );
463 spellmgr
.LoadSpellTargetPositions();
464 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
468 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
470 sLog
.outString( "Re-Loading Aggro Spells Definitions...");
471 spellmgr
.LoadSpellThreats();
472 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
476 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
478 sLog
.outString( "Re-Loading Spell pet auras...");
479 spellmgr
.LoadSpellPetAuras();
480 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
484 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
486 sLog
.outString( "Re-Loading Page Texts..." );
487 objmgr
.LoadPageTexts();
488 SendGlobalSysMessage("DB table `page_texts` reloaded.");
492 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
494 sLog
.outString( "Re-Loading Item Random Enchantments Table..." );
495 LoadRandomEnchantmentsTable();
496 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
500 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg
)
502 if(sWorld
.IsScriptScheduled())
504 SendSysMessage("DB scripts used currently, please attempt reload later.");
505 SetSentErrorMessage(true);
510 sLog
.outString( "Re-Loading Scripts from `gameobject_scripts`...");
512 objmgr
.LoadGameObjectScripts();
515 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
520 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg
)
522 if(sWorld
.IsScriptScheduled())
524 SendSysMessage("DB scripts used currently, please attempt reload later.");
525 SetSentErrorMessage(true);
530 sLog
.outString( "Re-Loading Scripts from `event_scripts`...");
532 objmgr
.LoadEventScripts();
535 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
540 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg
)
542 if(sWorld
.IsScriptScheduled())
544 SendSysMessage("DB scripts used currently, please attempt reload later.");
545 SetSentErrorMessage(true);
550 sLog
.outString( "Re-Loading Scripts from `quest_end_scripts`...");
552 objmgr
.LoadQuestEndScripts();
555 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
560 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg
)
562 if(sWorld
.IsScriptScheduled())
564 SendSysMessage("DB scripts used currently, please attempt reload later.");
565 SetSentErrorMessage(true);
570 sLog
.outString( "Re-Loading Scripts from `quest_start_scripts`...");
572 objmgr
.LoadQuestStartScripts();
575 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
580 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg
)
582 if(sWorld
.IsScriptScheduled())
584 SendSysMessage("DB scripts used currently, please attempt reload later.");
585 SetSentErrorMessage(true);
590 sLog
.outString( "Re-Loading Scripts from `spell_scripts`...");
592 objmgr
.LoadSpellScripts();
595 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
600 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
602 sLog
.outString( "Re-Loading Graveyard-zone links...");
604 objmgr
.LoadGraveyardZones();
606 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
611 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
613 sLog
.outString( "Re-Loading Game Tele coordinates...");
615 objmgr
.LoadGameTele();
617 SendGlobalSysMessage("DB table `game_tele` reloaded.");
622 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
624 sLog
.outString( "Re-Loading Locales Creature ...");
625 objmgr
.LoadCreatureLocales();
626 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
630 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
632 sLog
.outString( "Re-Loading Locales Gameobject ... ");
633 objmgr
.LoadGameObjectLocales();
634 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
638 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
640 sLog
.outString( "Re-Loading Locales Item ... ");
641 objmgr
.LoadItemLocales();
642 SendGlobalSysMessage("DB table `locales_item` reloaded.");
646 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
648 sLog
.outString( "Re-Loading Locales NPC Text ... ");
649 objmgr
.LoadNpcTextLocales();
650 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
654 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
656 sLog
.outString( "Re-Loading Locales Page Text ... ");
657 objmgr
.LoadPageTextLocales();
658 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
662 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
664 sLog
.outString( "Re-Loading Locales Quest ... ");
665 objmgr
.LoadQuestLocales();
666 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
670 bool ChatHandler::HandleLoadScriptsCommand(const char* args
)
672 if(!LoadScriptingModule(args
)) return true;
674 sWorld
.SendWorldText(LANG_SCRIPTS_RELOADED
);
678 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args
)
680 char* arg1
= strtok((char*)args
, " ");
684 /// must be NULL if targeted syntax and must be not nULL if not targeted
685 char* arg2
= strtok(NULL
, " ");
687 std::string targetAccountName
;
688 uint32 targetAccountId
= 0;
689 uint32 targetSecurity
= 0;
691 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
692 Player
* targetPlayer
= getSelectedPlayer();
693 if(targetPlayer
&& m_session
->GetPlayer()!=targetPlayer
)
695 /// wrong command syntax or unexpected targeting
699 /// security level expected in arg2 after this if.
702 targetAccountId
= targetPlayer
->GetSession()->GetAccountId();
703 targetSecurity
= targetPlayer
->GetSession()->GetSecurity();
704 if(!accmgr
.GetName(targetAccountId
,targetAccountName
))
706 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
707 SetSentErrorMessage(true);
713 /// wrong command syntax (second arg expected)
717 targetAccountName
= arg1
;
718 if(!AccountMgr::normilizeString(targetAccountName
))
720 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,targetAccountName
.c_str());
721 SetSentErrorMessage(true);
725 targetAccountId
= accmgr
.GetId(targetAccountName
);
726 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
729 int32 gm
= (int32
)atoi(arg2
);
730 if ( gm
< SEC_PLAYER
|| gm
> SEC_ADMINISTRATOR
)
732 SendSysMessage(LANG_BAD_VALUE
);
733 SetSentErrorMessage(true);
737 /// m_session==NULL only for console
738 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
740 /// can set security level only for target with less security and to less security that we have
741 /// This is also reject self apply in fact
742 if(targetSecurity
>= plSecurity
|| uint32(gm
) >= plSecurity
)
744 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW
);
745 SetSentErrorMessage(true);
751 ChatHandler(targetPlayer
).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED
,GetName(), gm
);
752 targetPlayer
->GetSession()->SetSecurity(gm
);
755 PSendSysMessage(LANG_YOU_CHANGE_SECURITY
, targetAccountName
.c_str(), gm
);
756 loginDatabase
.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm
, targetAccountId
);
761 /// Set password for account
762 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args
)
767 ///- Get the command line arguments
768 char *szAccount
= strtok ((char*)args
," ");
769 char *szPassword1
= strtok (NULL
," ");
770 char *szPassword2
= strtok (NULL
," ");
772 if (!szAccount
||!szPassword1
|| !szPassword2
)
775 std::string account_name
= szAccount
;
776 if(!AccountMgr::normilizeString(account_name
))
778 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
779 SetSentErrorMessage(true);
783 uint32 targetAccountId
= accmgr
.GetId(account_name
);
784 if (!targetAccountId
)
786 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
787 SetSentErrorMessage(true);
791 uint32 targetSecurity
= accmgr
.GetSecurity(targetAccountId
);
793 /// m_session==NULL only for console
794 uint32 plSecurity
= m_session
? m_session
->GetSecurity() : SEC_CONSOLE
;
796 /// can set password only for target with less security
797 /// This is also reject self apply in fact
798 if (targetSecurity
>= plSecurity
)
800 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW
);
801 SetSentErrorMessage (true);
805 if (strcmp(szPassword1
,szPassword2
))
807 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH
);
808 SetSentErrorMessage (true);
812 AccountOpResult result
= accmgr
.ChangePassword(targetAccountId
, szPassword1
);
817 SendSysMessage(LANG_COMMAND_PASSWORD
);
819 case AOR_NAME_NOT_EXIST
:
820 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
821 SetSentErrorMessage(true);
823 case AOR_PASS_TOO_LONG
:
824 SendSysMessage(LANG_PASSWORD_TOO_LONG
);
825 SetSentErrorMessage(true);
828 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD
);
829 SetSentErrorMessage(true);
836 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
838 if(sWorld
.getAllowMovement())
840 sWorld
.SetAllowMovement(false);
841 SendSysMessage(LANG_CREATURE_MOVE_DISABLED
);
845 sWorld
.SetAllowMovement(true);
846 SendSysMessage(LANG_CREATURE_MOVE_ENABLED
);
851 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
853 Player
* SelectedPlayer
= getSelectedPlayer();
856 SendSysMessage(LANG_NO_CHAR_SELECTED
);
857 SetSentErrorMessage(true);
861 // each skills that have max skill value dependent from level seted to current level max skill value
862 SelectedPlayer
->UpdateSkillsToMaxSkillsForLevel();
866 bool ChatHandler::HandleSetSkillCommand(const char* args
)
868 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
869 char* skill_p
= extractKeyFromLink((char*)args
,"Hskill");
873 char *level_p
= strtok (NULL
, " ");
878 char *max_p
= strtok (NULL
, " ");
880 int32 skill
= atoi(skill_p
);
884 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
885 SetSentErrorMessage(true);
889 int32 level
= atol (level_p
);
891 Player
* target
= getSelectedPlayer();
894 SendSysMessage(LANG_NO_CHAR_SELECTED
);
895 SetSentErrorMessage(true);
899 SkillLineEntry
const* sl
= sSkillLineStore
.LookupEntry(skill
);
902 PSendSysMessage(LANG_INVALID_SKILL_ID
, skill
);
903 SetSentErrorMessage(true);
907 if(!target
->GetSkillValue(skill
))
909 PSendSysMessage(LANG_SET_SKILL_ERROR
, target
->GetName(), skill
, sl
->name
[0]);
910 SetSentErrorMessage(true);
914 int32 max
= max_p
? atol (max_p
) : target
->GetPureMaxSkillValue(skill
);
916 if( level
<= 0 || level
> max
|| max
<= 0 )
919 target
->SetSkill(skill
, level
, max
);
920 PSendSysMessage(LANG_SET_SKILL
, skill
, sl
->name
[0], target
->GetName(), level
, max
);
925 bool ChatHandler::HandleUnLearnCommand(const char* args
)
930 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
931 uint32 min_id
= extractSpellIdFromLink((char*)args
);
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
936 char* tail
= strtok(NULL
,"");
938 uint32 max_id
= extractSpellIdFromLink(tail
);
942 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
948 std::swap(min_id
,max_id
);
953 Player
* target
= getSelectedPlayer();
956 SendSysMessage(LANG_NO_CHAR_SELECTED
);
957 SetSentErrorMessage(true);
961 for(uint32 spell
=min_id
;spell
<max_id
;spell
++)
963 if (target
->HasSpell(spell
))
964 target
->removeSpell(spell
);
966 SendSysMessage(LANG_FORGET_SPELL
);
972 bool ChatHandler::HandleCooldownCommand(const char* args
)
974 Player
* target
= getSelectedPlayer();
977 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
978 SetSentErrorMessage(true);
984 target
->RemoveAllSpellCooldown();
985 PSendSysMessage(LANG_REMOVEALL_COOLDOWN
, target
->GetName());
989 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
990 uint32 spell_id
= extractSpellIdFromLink((char*)args
);
994 if(!sSpellStore
.LookupEntry(spell_id
))
996 PSendSysMessage(LANG_UNKNOWN_SPELL
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
997 SetSentErrorMessage(true);
1001 WorldPacket
data( SMSG_CLEAR_COOLDOWN
, (4+8) );
1002 data
<< uint32(spell_id
);
1003 data
<< uint64(target
->GetGUID());
1004 target
->GetSession()->SendPacket(&data
);
1005 target
->RemoveSpellCooldown(spell_id
);
1006 PSendSysMessage(LANG_REMOVE_COOLDOWN
, spell_id
, target
==m_session
->GetPlayer() ? GetMangosString(LANG_YOU
) : target
->GetName());
1011 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1013 static const char *allSpellList
[] =
1396 //"9036", problems with ghost state
1405 //"6718", phasing stealth, annoying for learn all case.
1618 while(strcmp(allSpellList
[loop
], "0"))
1620 uint32 spell
= atol((char*)allSpellList
[loop
++]);
1622 if (m_session
->GetPlayer()->HasSpell(spell
))
1625 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1626 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1628 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1632 m_session
->GetPlayer()->learnSpell(spell
);
1635 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS
);
1640 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1642 static const char *gmSpellList
[] =
1644 "24347", // Become A Fish, No Breath Bar
1645 "35132", // Visual Boom
1646 "38488", // Attack 4000-8000 AOE
1647 "38795", // Attack 2000 AOE + Slow Down 90%
1648 "15712", // Attack 200
1649 "1852", // GM Spell Silence
1652 "29878", // Kill My Self
1653 "26644", // More Kill
1655 "28550", //Invisible 24
1656 "23452", //Invisible + Target
1660 uint16 gmSpellIter
= 0;
1661 while( strcmp(gmSpellList
[gmSpellIter
], "0") )
1663 uint32 spell
= atol((char*)gmSpellList
[gmSpellIter
++]);
1665 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1666 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1668 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1672 m_session
->GetPlayer()->learnSpell(spell
);
1675 SendSysMessage(LANG_LEARNING_GM_SKILLS
);
1679 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1681 HandleLearnAllMySpellsCommand("");
1682 HandleLearnAllMyTalentsCommand("");
1686 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1688 ChrClassesEntry
const* clsEntry
= sChrClassesStore
.LookupEntry(m_session
->GetPlayer()->getClass());
1691 uint32 family
= clsEntry
->spellfamily
;
1693 for (uint32 i
= 0; i
< sSpellStore
.GetNumRows(); i
++)
1695 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(i
);
1699 // skip wrong class/race skills
1700 if(!m_session
->GetPlayer()->IsSpellFitByClassAndRace(spellInfo
->Id
))
1703 // skip other spell families
1704 if( spellInfo
->SpellFamilyName
!= family
)
1707 //TODO: skip triggered spells
1709 // skip spells with first rank learned as talent (and all talents then also)
1710 uint32 first_rank
= spellmgr
.GetFirstSpellInChain(spellInfo
->Id
);
1711 if(GetTalentSpellCost(first_rank
) > 0 )
1714 // skip broken spells
1715 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1718 m_session
->GetPlayer()->learnSpell(i
);
1721 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS
);
1725 static void learnAllHighRanks(Player
* player
, uint32 spellid
)
1727 SpellChainMapNext
const& nextMap
= spellmgr
.GetSpellChainNext();
1728 for(SpellChainMapNext::const_iterator itr
= nextMap
.lower_bound(spellid
); itr
!= nextMap
.upper_bound(spellid
); ++itr
)
1730 player
->learnSpell(itr
->second
);
1731 learnAllHighRanks(player
,itr
->second
);
1735 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1737 Player
* player
= m_session
->GetPlayer();
1738 uint32 classMask
= player
->getClassMask();
1740 for (uint32 i
= 0; i
< sTalentStore
.GetNumRows(); i
++)
1742 TalentEntry
const *talentInfo
= sTalentStore
.LookupEntry(i
);
1746 TalentTabEntry
const *talentTabInfo
= sTalentTabStore
.LookupEntry( talentInfo
->TalentTab
);
1750 if( (classMask
& talentTabInfo
->ClassMask
) == 0 )
1753 // search highest talent rank
1756 for(; rank
>= 0; --rank
)
1758 if(talentInfo
->RankID
[rank
]!=0)
1760 spellid
= talentInfo
->RankID
[rank
];
1765 if(!spellid
) // ??? none spells in talent
1768 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spellid
);
1769 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer(),false))
1772 // learn highest rank of talent
1773 player
->learnSpell(spellid
);
1775 // and learn all non-talent spell ranks (recursive by tree)
1776 learnAllHighRanks(player
,spellid
);
1779 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS
);
1783 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1785 // skipping UNIVERSAL language (0)
1786 for(int i
= 1; i
< LANGUAGES_COUNT
; ++i
)
1787 m_session
->GetPlayer()->learnSpell(lang_description
[i
].spell_id
);
1789 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG
);
1793 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args
)
1795 char* pName
= strtok((char*)args
, "");
1796 Player
*player
= NULL
;
1799 std::string name
= pName
;
1801 if(!normalizePlayerName(name
))
1803 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1804 SetSentErrorMessage(true);
1808 player
= objmgr
.GetPlayer(name
.c_str());
1811 player
= getSelectedPlayer();
1815 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1816 SetSentErrorMessage(true);
1820 player
->learnDefaultSpells();
1821 player
->learnQuestRewardedSpells();
1823 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST
,player
->GetName());
1827 bool ChatHandler::HandleLearnCommand(const char* args
)
1829 Player
* targetPlayer
= getSelectedPlayer();
1833 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
1834 SetSentErrorMessage(true);
1838 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1839 uint32 spell
= extractSpellIdFromLink((char*)args
);
1840 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
1843 if (targetPlayer
->HasSpell(spell
))
1845 if(targetPlayer
== m_session
->GetPlayer())
1846 SendSysMessage(LANG_YOU_KNOWN_SPELL
);
1848 PSendSysMessage(LANG_TARGET_KNOWN_SPELL
,targetPlayer
->GetName());
1849 SetSentErrorMessage(true);
1853 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
1854 if(!spellInfo
|| !SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
1856 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
1857 SetSentErrorMessage(true);
1861 targetPlayer
->learnSpell(spell
);
1866 bool ChatHandler::HandleAddItemCommand(const char* args
)
1873 if(args
[0]=='[') // [name] manual form
1875 char* citemName
= citemName
= strtok((char*)args
, "]");
1877 if(citemName
&& citemName
[0])
1879 std::string itemName
= citemName
+1;
1880 WorldDatabase
.escape_string(itemName
);
1881 QueryResult
*result
= WorldDatabase
.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName
.c_str());
1884 PSendSysMessage(LANG_COMMAND_COULDNOTFIND
, citemName
+1);
1885 SetSentErrorMessage(true);
1888 itemId
= result
->Fetch()->GetUInt16();
1894 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1896 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
1902 char* ccount
= strtok(NULL
, " ");
1907 count
= strtol(ccount
, NULL
, 10);
1912 Player
* pl
= m_session
->GetPlayer();
1913 Player
* plTarget
= getSelectedPlayer();
1917 sLog
.outDetail(GetMangosString(LANG_ADDITEM
), itemId
, count
);
1919 ItemPrototype
const *pProto
= objmgr
.GetItemPrototype(itemId
);
1922 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, itemId
);
1923 SetSentErrorMessage(true);
1930 plTarget
->DestroyItemCount(itemId
, -count
, true, false);
1931 PSendSysMessage(LANG_REMOVEITEM
, itemId
, -count
, plTarget
->GetName());
1936 uint32 noSpaceForCount
= 0;
1938 // check space and find places
1939 ItemPosCountVec dest
;
1940 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, itemId
, count
, &noSpaceForCount
);
1941 if( msg
!= EQUIP_ERR_OK
) // convert to possible store amount
1942 count
-= noSpaceForCount
;
1944 if( count
== 0 || dest
.empty()) // can't add any
1946 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1947 SetSentErrorMessage(true);
1951 Item
* item
= plTarget
->StoreNewItem( dest
, itemId
, true, Item::GenerateItemRandomPropertyId(itemId
));
1953 // remove binding (let GM give it to another player later)
1955 for(ItemPosCountVec::const_iterator itr
= dest
.begin(); itr
!= dest
.end(); ++itr
)
1956 if(Item
* item1
= pl
->GetItemByPos(itr
->pos
))
1957 item1
->SetBinding( false );
1959 if(count
> 0 && item
)
1961 pl
->SendNewItem(item
,count
,false,true);
1963 plTarget
->SendNewItem(item
,count
,true,false);
1966 if(noSpaceForCount
> 0)
1967 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, itemId
, noSpaceForCount
);
1972 bool ChatHandler::HandleAddItemSetCommand(const char* args
)
1977 char* cId
= extractKeyFromLink((char*)args
,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1981 uint32 itemsetId
= atol(cId
);
1983 // prevent generation all items with itemset field value '0'
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
1987 SetSentErrorMessage(true);
1991 Player
* pl
= m_session
->GetPlayer();
1992 Player
* plTarget
= getSelectedPlayer();
1996 sLog
.outDetail(GetMangosString(LANG_ADDITEMSET
), itemsetId
);
1999 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2001 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2005 if (pProto
->ItemSet
== itemsetId
)
2008 ItemPosCountVec dest
;
2009 uint8 msg
= plTarget
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, pProto
->ItemId
, 1 );
2010 if (msg
== EQUIP_ERR_OK
)
2012 Item
* item
= plTarget
->StoreNewItem( dest
, pProto
->ItemId
, true);
2014 // remove binding (let GM give it to another player later)
2016 item
->SetBinding( false );
2018 pl
->SendNewItem(item
,1,false,true);
2020 plTarget
->SendNewItem(item
,1,true,false);
2024 pl
->SendEquipError( msg
, NULL
, NULL
);
2025 PSendSysMessage(LANG_ITEM_CANNOT_CREATE
, pProto
->ItemId
, 1);
2032 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND
,itemsetId
);
2034 SetSentErrorMessage(true);
2041 bool ChatHandler::HandleListItemCommand(const char* args
)
2046 char* cId
= extractKeyFromLink((char*)args
,"Hitem");
2050 uint32 item_id
= atol(cId
);
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2054 SetSentErrorMessage(true);
2058 ItemPrototype
const* itemProto
= objmgr
.GetItemPrototype(item_id
);
2061 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
2062 SetSentErrorMessage(true);
2066 char* c_count
= strtok(NULL
, " ");
2067 int count
= c_count
? atol(c_count
) : 10;
2072 QueryResult
*result
;
2075 uint32 inv_count
= 0;
2076 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id
);
2079 inv_count
= (*result
)[0].GetUInt32();
2083 result
=CharacterDatabase
.PQuery(
2085 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2086 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2087 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2088 item_id
,uint32(count
));
2094 Field
*fields
= result
->Fetch();
2095 uint32 item_guid
= fields
[0].GetUInt32();
2096 uint32 item_bag
= fields
[1].GetUInt32();
2097 uint32 item_slot
= fields
[2].GetUInt32();
2098 uint32 owner_guid
= fields
[3].GetUInt32();
2099 uint32 owner_acc
= fields
[4].GetUInt32();
2100 std::string owner_name
= fields
[5].GetCppString();
2102 char const* item_pos
= 0;
2103 if(Player::IsEquipmentPos(item_bag
,item_slot
))
2104 item_pos
= "[equipped]";
2105 else if(Player::IsInventoryPos(item_bag
,item_slot
))
2106 item_pos
= "[in inventory]";
2107 else if(Player::IsBankPos(item_bag
,item_slot
))
2108 item_pos
= "[in bank]";
2112 PSendSysMessage(LANG_ITEMLIST_SLOT
,
2113 item_guid
,owner_name
.c_str(),owner_guid
,owner_acc
,item_pos
);
2114 } while (result
->NextRow());
2116 int64 res_count
= result
->GetRowCount();
2120 if(count
> res_count
)
2127 uint32 mail_count
= 0;
2128 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id
);
2131 mail_count
= (*result
)[0].GetUInt32();
2137 result
=CharacterDatabase
.PQuery(
2139 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2140 "FROM mail,mail_items,characters as char_s,characters as char_r "
2141 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2142 item_id
,uint32(count
));
2151 Field
*fields
= result
->Fetch();
2152 uint32 item_guid
= fields
[0].GetUInt32();
2153 uint32 item_s
= fields
[1].GetUInt32();
2154 uint32 item_r
= fields
[2].GetUInt32();
2155 uint32 item_s_acc
= fields
[3].GetUInt32();
2156 std::string item_s_name
= fields
[4].GetCppString();
2157 uint32 item_r_acc
= fields
[5].GetUInt32();
2158 std::string item_r_name
= fields
[6].GetCppString();
2160 char const* item_pos
= "[in mail]";
2162 PSendSysMessage(LANG_ITEMLIST_MAIL
,
2163 item_guid
,item_s_name
.c_str(),item_s
,item_s_acc
,item_r_name
.c_str(),item_r
,item_r_acc
,item_pos
);
2164 } while (result
->NextRow());
2166 int64 res_count
= result
->GetRowCount();
2170 if(count
> res_count
)
2177 uint32 auc_count
= 0;
2178 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id
);
2181 auc_count
= (*result
)[0].GetUInt32();
2187 result
=CharacterDatabase
.PQuery(
2189 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2190 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2191 item_id
,uint32(count
));
2200 Field
*fields
= result
->Fetch();
2201 uint32 item_guid
= fields
[0].GetUInt32();
2202 uint32 owner
= fields
[1].GetUInt32();
2203 uint32 owner_acc
= fields
[2].GetUInt32();
2204 std::string owner_name
= fields
[3].GetCppString();
2206 char const* item_pos
= "[in auction]";
2208 PSendSysMessage(LANG_ITEMLIST_AUCTION
, item_guid
, owner_name
.c_str(), owner
, owner_acc
,item_pos
);
2209 } while (result
->NextRow());
2215 uint32 guild_count
= 0;
2216 result
=CharacterDatabase
.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id
);
2219 guild_count
= (*result
)[0].GetUInt32();
2223 result
=CharacterDatabase
.PQuery(
2225 "SELECT gi.item_guid, gi.guildid, guild.name "
2226 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2227 item_id
,uint32(count
));
2233 Field
*fields
= result
->Fetch();
2234 uint32 item_guid
= fields
[0].GetUInt32();
2235 uint32 guild_guid
= fields
[1].GetUInt32();
2236 std::string guild_name
= fields
[2].GetCppString();
2238 char const* item_pos
= "[in guild bank]";
2240 PSendSysMessage(LANG_ITEMLIST_GUILD
,item_guid
,guild_name
.c_str(),guild_guid
,item_pos
);
2241 } while (result
->NextRow());
2243 int64 res_count
= result
->GetRowCount();
2247 if(count
> res_count
)
2253 if(inv_count
+mail_count
+auc_count
+guild_count
== 0)
2255 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2256 SetSentErrorMessage(true);
2260 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE
,item_id
,inv_count
+mail_count
+auc_count
+guild_count
,inv_count
,mail_count
,auc_count
,guild_count
);
2265 bool ChatHandler::HandleListObjectCommand(const char* args
)
2270 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2271 char* cId
= extractKeyFromLink((char*)args
,"Hgameobject_entry");
2275 uint32 go_id
= atol(cId
);
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2279 SetSentErrorMessage(true);
2283 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(go_id
);
2286 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID
, go_id
);
2287 SetSentErrorMessage(true);
2291 char* c_count
= strtok(NULL
, " ");
2292 int count
= c_count
? atol(c_count
) : 10;
2297 QueryResult
*result
;
2299 uint32 obj_count
= 0;
2300 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id
);
2303 obj_count
= (*result
)[0].GetUInt32();
2309 Player
* pl
= m_session
->GetPlayer();
2310 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2311 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),go_id
,uint32(count
));
2314 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2315 go_id
,uint32(count
));
2321 Field
*fields
= result
->Fetch();
2322 uint32 guid
= fields
[0].GetUInt32();
2323 float x
= fields
[1].GetFloat();
2324 float y
= fields
[2].GetFloat();
2325 float z
= fields
[3].GetFloat();
2326 int mapid
= fields
[4].GetUInt16();
2329 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2331 PSendSysMessage(LANG_GO_LIST_CONSOLE
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2332 } while (result
->NextRow());
2337 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE
,go_id
,obj_count
);
2341 bool ChatHandler::HandleNearObjectCommand(const char* args
)
2343 float distance
= (!*args
) ? 10 : atol(args
);
2346 Player
* pl
= m_session
->GetPlayer();
2347 QueryResult
*result
= WorldDatabase
.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2348 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2349 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2350 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),
2351 pl
->GetMapId(),pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(),distance
*distance
);
2357 Field
*fields
= result
->Fetch();
2358 uint32 guid
= fields
[0].GetUInt32();
2359 uint32 entry
= fields
[1].GetUInt32();
2360 float x
= fields
[2].GetFloat();
2361 float y
= fields
[3].GetFloat();
2362 float z
= fields
[4].GetFloat();
2363 int mapid
= fields
[5].GetUInt16();
2365 GameObjectInfo
const * gInfo
= objmgr
.GetGameObjectInfo(entry
);
2370 PSendSysMessage(LANG_GO_LIST_CHAT
, guid
, guid
, gInfo
->name
, x
, y
, z
, mapid
);
2373 } while (result
->NextRow());
2378 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE
,distance
,count
);
2382 bool ChatHandler::HandleListCreatureCommand(const char* args
)
2387 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2388 char* cId
= extractKeyFromLink((char*)args
,"Hcreature_entry");
2392 uint32 cr_id
= atol(cId
);
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2396 SetSentErrorMessage(true);
2400 CreatureInfo
const* cInfo
= objmgr
.GetCreatureTemplate(cr_id
);
2403 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID
, cr_id
);
2404 SetSentErrorMessage(true);
2408 char* c_count
= strtok(NULL
, " ");
2409 int count
= c_count
? atol(c_count
) : 10;
2414 QueryResult
*result
;
2416 uint32 cr_count
= 0;
2417 result
=WorldDatabase
.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id
);
2420 cr_count
= (*result
)[0].GetUInt32();
2426 Player
* pl
= m_session
->GetPlayer();
2427 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2428 pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ(), cr_id
,uint32(count
));
2431 result
= WorldDatabase
.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2432 cr_id
,uint32(count
));
2438 Field
*fields
= result
->Fetch();
2439 uint32 guid
= fields
[0].GetUInt32();
2440 float x
= fields
[1].GetFloat();
2441 float y
= fields
[2].GetFloat();
2442 float z
= fields
[3].GetFloat();
2443 int mapid
= fields
[4].GetUInt16();
2446 PSendSysMessage(LANG_CREATURE_LIST_CHAT
, guid
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2448 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE
, guid
, cInfo
->Name
, x
, y
, z
, mapid
);
2449 } while (result
->NextRow());
2454 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE
,cr_id
,cr_count
);
2458 bool ChatHandler::HandleLookupItemCommand(const char* args
)
2463 std::string namepart
= args
;
2464 std::wstring wnamepart
;
2466 // converting string that we try to find to lower case
2467 if(!Utf8toWStr(namepart
,wnamepart
))
2470 wstrToLower(wnamepart
);
2474 // Search in `item_template`
2475 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
2477 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
2481 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2484 ItemLocale
const *il
= objmgr
.GetItemLocale(pProto
->ItemId
);
2487 if (il
->Name
.size() > loc_idx
&& !il
->Name
[loc_idx
].empty())
2489 std::string name
= il
->Name
[loc_idx
];
2491 if (Utf8FitTo(name
, wnamepart
))
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2504 std::string name
= pProto
->Name1
;
2508 if (Utf8FitTo(name
, wnamepart
))
2511 PSendSysMessage(LANG_ITEM_LIST_CHAT
, id
, id
, name
.c_str());
2513 PSendSysMessage(LANG_ITEM_LIST_CONSOLE
, id
, name
.c_str());
2519 SendSysMessage(LANG_COMMAND_NOITEMFOUND
);
2524 bool ChatHandler::HandleLookupItemSetCommand(const char* args
)
2529 std::string namepart
= args
;
2530 std::wstring wnamepart
;
2532 if(!Utf8toWStr(namepart
,wnamepart
))
2535 // converting string that we try to find to lower case
2536 wstrToLower( wnamepart
);
2538 uint32 counter
= 0; // Counter for figure out that we found smth.
2540 // Search in ItemSet.dbc
2541 for (uint32 id
= 0; id
< sItemSetStore
.GetNumRows(); id
++)
2543 ItemSetEntry
const *set
= sItemSetStore
.LookupEntry(id
);
2546 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2547 std::string name
= set
->name
[loc
];
2551 if (!Utf8FitTo(name
, wnamepart
))
2554 for(; loc
< MAX_LOCALE
; ++loc
)
2556 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2559 name
= set
->name
[loc
];
2563 if (Utf8FitTo(name
, wnamepart
))
2568 if(loc
< MAX_LOCALE
)
2570 // send item set in "id - [namedlink locale]" format
2572 PSendSysMessage(LANG_ITEMSET_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
]);
2574 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
]);
2579 if (counter
== 0) // if counter == 0 then we found nth
2580 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND
);
2584 bool ChatHandler::HandleLookupSkillCommand(const char* args
)
2589 // can be NULL in console call
2590 Player
* target
= getSelectedPlayer();
2592 std::string namepart
= args
;
2593 std::wstring wnamepart
;
2595 if(!Utf8toWStr(namepart
,wnamepart
))
2598 // converting string that we try to find to lower case
2599 wstrToLower( wnamepart
);
2601 uint32 counter
= 0; // Counter for figure out that we found smth.
2603 // Search in SkillLine.dbc
2604 for (uint32 id
= 0; id
< sSkillLineStore
.GetNumRows(); id
++)
2606 SkillLineEntry
const *skillInfo
= sSkillLineStore
.LookupEntry(id
);
2609 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2610 std::string name
= skillInfo
->name
[loc
];
2614 if (!Utf8FitTo(name
, wnamepart
))
2617 for(; loc
< MAX_LOCALE
; ++loc
)
2619 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2622 name
= skillInfo
->name
[loc
];
2626 if (Utf8FitTo(name
, wnamepart
))
2631 if(loc
< MAX_LOCALE
)
2633 char const* knownStr
= "";
2634 if(target
&& target
->HasSkill(id
))
2635 knownStr
= GetMangosString(LANG_KNOWN
);
2637 // send skill in "id - [namedlink locale]" format
2639 PSendSysMessage(LANG_SKILL_LIST_CHAT
,id
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2641 PSendSysMessage(LANG_SKILL_LIST_CONSOLE
,id
,name
.c_str(),localeNames
[loc
],knownStr
);
2647 if (counter
== 0) // if counter == 0 then we found nth
2648 SendSysMessage(LANG_COMMAND_NOSKILLFOUND
);
2652 bool ChatHandler::HandleLookupSpellCommand(const char* args
)
2657 // can be NULL at console call
2658 Player
* target
= getSelectedPlayer();
2660 std::string namepart
= args
;
2661 std::wstring wnamepart
;
2663 if(!Utf8toWStr(namepart
,wnamepart
))
2666 // converting string that we try to find to lower case
2667 wstrToLower( wnamepart
);
2669 uint32 counter
= 0; // Counter for figure out that we found smth.
2671 // Search in Spell.dbc
2672 for (uint32 id
= 0; id
< sSpellStore
.GetNumRows(); id
++)
2674 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry(id
);
2677 int loc
= m_session
? m_session
->GetSessionDbcLocale() : sWorld
.GetDefaultDbcLocale();
2678 std::string name
= spellInfo
->SpellName
[loc
];
2682 if (!Utf8FitTo(name
, wnamepart
))
2685 for(; loc
< MAX_LOCALE
; ++loc
)
2687 if(m_session
&& loc
==m_session
->GetSessionDbcLocale())
2690 name
= spellInfo
->SpellName
[loc
];
2694 if (Utf8FitTo(name
, wnamepart
))
2699 if(loc
< MAX_LOCALE
)
2701 bool known
= target
&& target
->HasSpell(id
);
2702 bool learn
= (spellInfo
->Effect
[0] == SPELL_EFFECT_LEARN_SPELL
);
2704 uint32 talentCost
= GetTalentSpellCost(id
);
2706 bool talent
= (talentCost
> 0);
2707 bool passive
= IsPassiveSpell(id
);
2708 bool active
= target
&& (target
->HasAura(id
,0) || target
->HasAura(id
,1) || target
->HasAura(id
,2));
2710 // unit32 used to prevent interpreting uint8 as char at output
2711 // find rank of learned spell for learning spell, or talent rank
2712 uint32 rank
= talentCost
? talentCost
: spellmgr
.GetSpellRank(learn
? spellInfo
->EffectTriggerSpell
[0] : id
);
2714 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2715 std::ostringstream ss
;
2717 ss
<< id
<< " - |cffffffff|Hspell:" << id
<< "|h[" << name
;
2719 ss
<< id
<< " - " << name
;
2721 // include rank in link name
2723 ss
<< GetMangosString(LANG_SPELL_RANK
) << rank
;
2726 ss
<< " " << localeNames
[loc
] << "]|h|r";
2728 ss
<< " " << localeNames
[loc
];
2731 ss
<< GetMangosString(LANG_TALENT
);
2733 ss
<< GetMangosString(LANG_PASSIVE
);
2735 ss
<< GetMangosString(LANG_LEARN
);
2737 ss
<< GetMangosString(LANG_KNOWN
);
2739 ss
<< GetMangosString(LANG_ACTIVE
);
2741 SendSysMessage(ss
.str().c_str());
2747 if (counter
== 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSPELLFOUND
);
2752 bool ChatHandler::HandleLookupQuestCommand(const char* args
)
2757 // can be NULL at console call
2758 Player
* target
= getSelectedPlayer();
2760 std::string namepart
= args
;
2761 std::wstring wnamepart
;
2763 // converting string that we try to find to lower case
2764 if(!Utf8toWStr(namepart
,wnamepart
))
2767 wstrToLower(wnamepart
);
2769 uint32 counter
= 0 ;
2771 ObjectMgr::QuestMap
const& qTemplates
= objmgr
.GetQuestTemplates();
2772 for (ObjectMgr::QuestMap::const_iterator iter
= qTemplates
.begin(); iter
!= qTemplates
.end(); ++iter
)
2774 Quest
* qinfo
= iter
->second
;
2776 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2779 QuestLocale
const *il
= objmgr
.GetQuestLocale(qinfo
->GetQuestId());
2782 if (il
->Title
.size() > loc_idx
&& !il
->Title
[loc_idx
].empty())
2784 std::string title
= il
->Title
[loc_idx
];
2786 if (Utf8FitTo(title
, wnamepart
))
2788 char const* statusStr
= "";
2792 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2794 if(status
== QUEST_STATUS_COMPLETE
)
2796 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2797 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2799 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2801 else if(status
== QUEST_STATUS_INCOMPLETE
)
2802 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2806 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2808 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2816 std::string title
= qinfo
->GetTitle();
2820 if (Utf8FitTo(title
, wnamepart
))
2822 char const* statusStr
= "";
2826 QuestStatus status
= target
->GetQuestStatus(qinfo
->GetQuestId());
2828 if(status
== QUEST_STATUS_COMPLETE
)
2830 if(target
->GetQuestRewardStatus(qinfo
->GetQuestId()))
2831 statusStr
= GetMangosString(LANG_COMMAND_QUEST_REWARDED
);
2833 statusStr
= GetMangosString(LANG_COMMAND_QUEST_COMPLETE
);
2835 else if(status
== QUEST_STATUS_INCOMPLETE
)
2836 statusStr
= GetMangosString(LANG_COMMAND_QUEST_ACTIVE
);
2840 PSendSysMessage(LANG_QUEST_LIST_CHAT
,qinfo
->GetQuestId(),qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2842 PSendSysMessage(LANG_QUEST_LIST_CONSOLE
,qinfo
->GetQuestId(),title
.c_str(),statusStr
);
2849 SendSysMessage(LANG_COMMAND_NOQUESTFOUND
);
2854 bool ChatHandler::HandleLookupCreatureCommand(const char* args
)
2859 std::string namepart
= args
;
2860 std::wstring wnamepart
;
2862 // converting string that we try to find to lower case
2863 if (!Utf8toWStr (namepart
,wnamepart
))
2866 wstrToLower (wnamepart
);
2870 for (uint32 id
= 0; id
< sCreatureStorage
.MaxEntry
; ++id
)
2872 CreatureInfo
const* cInfo
= sCreatureStorage
.LookupEntry
<CreatureInfo
> (id
);
2876 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2879 CreatureLocale
const *cl
= objmgr
.GetCreatureLocale (id
);
2882 if (cl
->Name
.size() > loc_idx
&& !cl
->Name
[loc_idx
].empty ())
2884 std::string name
= cl
->Name
[loc_idx
];
2886 if (Utf8FitTo (name
, wnamepart
))
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2899 std::string name
= cInfo
->Name
;
2903 if (Utf8FitTo(name
, wnamepart
))
2906 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT
, id
, id
, name
.c_str ());
2908 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE
, id
, name
.c_str ());
2914 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND
);
2919 bool ChatHandler::HandleLookupObjectCommand(const char* args
)
2924 std::string namepart
= args
;
2925 std::wstring wnamepart
;
2927 // converting string that we try to find to lower case
2928 if(!Utf8toWStr(namepart
,wnamepart
))
2931 wstrToLower(wnamepart
);
2935 for (uint32 id
= 0; id
< sGOStorage
.MaxEntry
; id
++ )
2937 GameObjectInfo
const* gInfo
= sGOStorage
.LookupEntry
<GameObjectInfo
>(id
);
2941 int loc_idx
= m_session
? m_session
->GetSessionDbLocaleIndex() : objmgr
.GetDBCLocaleIndex();
2944 GameObjectLocale
const *gl
= objmgr
.GetGameObjectLocale(id
);
2947 if (gl
->Name
.size() > loc_idx
&& !gl
->Name
[loc_idx
].empty())
2949 std::string name
= gl
->Name
[loc_idx
];
2951 if (Utf8FitTo(name
, wnamepart
))
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2964 std::string name
= gInfo
->name
;
2968 if(Utf8FitTo(name
, wnamepart
))
2971 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT
, id
, id
, name
.c_str());
2973 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE
, id
, name
.c_str());
2979 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND
);
2984 /** \brief GM command level 3 - Create a guild.
2986 * This command allows a GM (level 3) to create a guild.
2988 * The "args" parameter contains the name of the guild leader
2989 * and then the name of the guild.
2992 bool ChatHandler::HandleGuildCreateCommand(const char* args
)
2998 char *lname
= strtok ((char*)args
, " ");
2999 char *gname
= strtok (NULL
, "");
3006 SendSysMessage (LANG_INSERT_GUILD_NAME
);
3007 SetSentErrorMessage (true);
3011 std::string guildname
= gname
;
3013 Player
* player
= ObjectAccessor::Instance ().FindPlayerByName (lname
);
3016 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3017 SetSentErrorMessage (true);
3021 if (player
->GetGuildId())
3023 SendSysMessage (LANG_PLAYER_IN_GUILD
);
3027 Guild
*guild
= new Guild
;
3028 if (!guild
->create (player
->GetGUID (),guildname
))
3031 SendSysMessage (LANG_GUILD_NOT_CREATED
);
3032 SetSentErrorMessage (true);
3036 objmgr
.AddGuild (guild
);
3040 bool ChatHandler::HandleGuildInviteCommand(const char *args
)
3045 char* par1
= strtok ((char*)args
, " ");
3046 char* par2
= strtok (NULL
, "");
3050 std::string glName
= par2
;
3051 Guild
* targetGuild
= objmgr
.GetGuildByName (glName
);
3055 std::string plName
= par1
;
3056 if (!normalizePlayerName (plName
))
3058 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3059 SetSentErrorMessage (true);
3064 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3065 plGuid
= targetPlayer
->GetGUID ();
3067 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3072 // player's guild membership checked in AddMember before add
3073 if (!targetGuild
->AddMember (plGuid
,targetGuild
->GetLowestRank ()))
3079 bool ChatHandler::HandleGuildUninviteCommand(const char *args
)
3084 char* par1
= strtok ((char*)args
, " ");
3088 std::string plName
= par1
;
3089 if (!normalizePlayerName (plName
))
3091 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3092 SetSentErrorMessage (true);
3098 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3100 plGuid
= targetPlayer
->GetGUID ();
3101 glId
= targetPlayer
->GetGuildId ();
3105 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3106 glId
= Player::GetGuildIdFromDB (plGuid
);
3109 if (!plGuid
|| !glId
)
3112 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3116 targetGuild
->DelMember (plGuid
);
3121 bool ChatHandler::HandleGuildRankCommand(const char *args
)
3126 char* par1
= strtok ((char*)args
, " ");
3127 char* par2
= strtok (NULL
, " ");
3130 std::string plName
= par1
;
3131 if (!normalizePlayerName (plName
))
3133 SendSysMessage (LANG_PLAYER_NOT_FOUND
);
3134 SetSentErrorMessage (true);
3140 if (Player
* targetPlayer
= ObjectAccessor::Instance ().FindPlayerByName (plName
.c_str ()))
3142 plGuid
= targetPlayer
->GetGUID ();
3143 glId
= targetPlayer
->GetGuildId ();
3147 plGuid
= objmgr
.GetPlayerGUIDByName (plName
.c_str ());
3148 glId
= Player::GetGuildIdFromDB (plGuid
);
3151 if (!plGuid
|| !glId
)
3154 Guild
* targetGuild
= objmgr
.GetGuildById (glId
);
3158 uint32 newrank
= uint32 (atoi (par2
));
3159 if (newrank
> targetGuild
->GetLowestRank ())
3162 targetGuild
->ChangeRank (plGuid
,newrank
);
3167 bool ChatHandler::HandleGuildDeleteCommand(const char* args
)
3172 char* par1
= strtok ((char*)args
, " ");
3176 std::string gld
= par1
;
3178 Guild
* targetGuild
= objmgr
.GetGuildByName (gld
);
3182 targetGuild
->Disband ();
3187 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3189 Unit
* pUnit
= getSelectedUnit();
3193 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3194 SetSentErrorMessage(true);
3198 PSendSysMessage(LANG_DISTANCE
, m_session
->GetPlayer()->GetDistance(pUnit
),m_session
->GetPlayer()->GetDistance2d(pUnit
));
3205 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3210 uint64 guid = m_session->GetPlayer()->GetSelection();
3213 SendSysMessage(LANG_NO_SELECTION);
3217 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3221 SendSysMessage(LANG_SELECT_CREATURE);
3225 char* pSlotID = strtok((char*)args, " ");
3229 char* pItemID = strtok(NULL, " ");
3233 uint32 ItemID = atoi(pItemID);
3234 uint32 SlotID = atoi(pSlotID);
3236 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3248 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3252 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3256 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3262 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3267 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3274 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3276 Unit
* target
= getSelectedUnit();
3278 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3280 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3281 SetSentErrorMessage(true);
3285 if( target
->isAlive() )
3287 m_session
->GetPlayer()->DealDamage(target
, target
->GetHealth(), NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3293 bool ChatHandler::HandleDamageCommand(const char * args
)
3298 Unit
* target
= getSelectedUnit();
3300 if(!target
|| !m_session
->GetPlayer()->GetSelection())
3302 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3303 SetSentErrorMessage(true);
3307 if( !target
->isAlive() )
3310 char* damageStr
= strtok((char*)args
, " ");
3314 int32 damage
= atoi((char*)damageStr
);
3318 char* schoolStr
= strtok((char*)NULL
, " ");
3320 // flat melee damage without resistence/etc reduction
3323 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, SPELL_SCHOOL_MASK_NORMAL
, NULL
, false);
3324 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, SPELL_SCHOOL_MASK_NORMAL
, damage
, 0, 0, VICTIMSTATE_NORMAL
, 0);
3328 uint32 school
= schoolStr
? atoi((char*)schoolStr
) : SPELL_SCHOOL_NORMAL
;
3329 if(school
>= MAX_SPELL_SCHOOL
)
3332 SpellSchoolMask schoolmask
= SpellSchoolMask(1 << school
);
3334 if ( schoolmask
& SPELL_SCHOOL_MASK_NORMAL
)
3335 damage
= m_session
->GetPlayer()->CalcArmorReducedDamage(target
, damage
);
3337 char* spellStr
= strtok((char*)NULL
, " ");
3339 // melee damage by specific school
3345 m_session
->GetPlayer()->CalcAbsorbResist(target
,schoolmask
, SPELL_DIRECT_DAMAGE
, damage
, &absorb
, &resist
);
3347 if (damage
<= absorb
+ resist
)
3350 damage
-= absorb
+ resist
;
3352 m_session
->GetPlayer()->DealDamage(target
, damage
, NULL
, DIRECT_DAMAGE
, schoolmask
, NULL
, false);
3353 m_session
->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2
, target
, 1, schoolmask
, damage
, absorb
, resist
, VICTIMSTATE_NORMAL
, 0);
3359 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3360 uint32 spellid
= extractSpellIdFromLink((char*)args
);
3361 if(!spellid
|| !sSpellStore
.LookupEntry(spellid
))
3364 m_session
->GetPlayer()->SpellNonMeleeDamageLog(target
, spellid
, damage
, false);
3368 bool ChatHandler::HandleModifyArenaCommand(const char * args
)
3373 Player
*target
= getSelectedPlayer();
3376 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3377 SetSentErrorMessage(true);
3381 int32 amount
= (uint32
)atoi(args
);
3383 target
->ModifyArenaPoints(amount
);
3385 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA
, target
->GetName(), target
->GetArenaPoints());
3390 bool ChatHandler::HandleReviveCommand(const char* args
)
3392 Player
* SelectedPlayer
= NULL
;
3396 std::string name
= args
;
3397 if(!normalizePlayerName(name
))
3399 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3400 SetSentErrorMessage(true);
3404 SelectedPlayer
= objmgr
.GetPlayer(name
.c_str());
3407 SelectedPlayer
= getSelectedPlayer();
3411 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3412 SetSentErrorMessage(true);
3416 SelectedPlayer
->ResurrectPlayer(0.5f
);
3417 SelectedPlayer
->SpawnCorpseBones();
3418 SelectedPlayer
->SaveToDB();
3422 bool ChatHandler::HandleAuraCommand(const char* args
)
3424 char* px
= strtok((char*)args
, " ");
3428 Unit
*target
= getSelectedUnit();
3431 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3432 SetSentErrorMessage(true);
3436 uint32 spellID
= (uint32
)atoi(px
);
3437 SpellEntry
const *spellInfo
= sSpellStore
.LookupEntry( spellID
);
3440 for(uint32 i
= 0;i
<3;i
++)
3442 uint8 eff
= spellInfo
->Effect
[i
];
3443 if (eff
>=TOTAL_SPELL_EFFECTS
)
3445 if( IsAreaAuraEffect(eff
) ||
3446 eff
== SPELL_EFFECT_APPLY_AURA
||
3447 eff
== SPELL_EFFECT_PERSISTENT_AREA_AURA
)
3449 Aura
*Aur
= CreateAura(spellInfo
, i
, NULL
, target
);
3450 target
->AddAura(Aur
);
3458 bool ChatHandler::HandleUnAuraCommand(const char* args
)
3460 char* px
= strtok((char*)args
, " ");
3464 Unit
*target
= getSelectedUnit();
3467 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3468 SetSentErrorMessage(true);
3472 std::string argstr
= args
;
3473 if (argstr
== "all")
3475 target
->RemoveAllAuras();
3479 uint32 spellID
= (uint32
)atoi(px
);
3480 target
->RemoveAurasDueToSpell(spellID
);
3485 bool ChatHandler::HandleLinkGraveCommand(const char* args
)
3490 char* px
= strtok((char*)args
, " ");
3494 uint32 g_id
= (uint32
)atoi(px
);
3498 char* px2
= strtok(NULL
, " ");
3502 else if (strncmp(px2
,"horde",6)==0)
3504 else if (strncmp(px2
,"alliance",9)==0)
3509 WorldSafeLocsEntry
const* graveyard
= sWorldSafeLocsStore
.LookupEntry(g_id
);
3513 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST
, g_id
);
3514 SetSentErrorMessage(true);
3518 Player
* player
= m_session
->GetPlayer();
3520 uint32 zoneId
= player
->GetZoneId();
3522 AreaTableEntry
const *areaEntry
= GetAreaEntryByAreaID(zoneId
);
3523 if(!areaEntry
|| areaEntry
->zone
!=0 )
3525 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE
, g_id
,zoneId
);
3526 SetSentErrorMessage(true);
3530 if(objmgr
.AddGraveYardLink(g_id
,player
->GetZoneId(),g_team
))
3531 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED
, g_id
,zoneId
);
3533 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED
, g_id
,zoneId
);
3538 bool ChatHandler::HandleNearGraveCommand(const char* args
)
3542 size_t argslen
= strlen(args
);
3546 else if (strncmp((char*)args
,"horde",argslen
)==0)
3548 else if (strncmp((char*)args
,"alliance",argslen
)==0)
3553 Player
* player
= m_session
->GetPlayer();
3555 WorldSafeLocsEntry
const* graveyard
= objmgr
.GetClosestGraveYard(
3556 player
->GetPositionX(), player
->GetPositionY(), player
->GetPositionZ(),player
->GetMapId(),g_team
);
3560 uint32 g_id
= graveyard
->ID
;
3562 GraveYardData
const* data
= objmgr
.FindGraveYardData(g_id
,player
->GetZoneId());
3565 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR
,g_id
);
3566 SetSentErrorMessage(true);
3570 g_team
= data
->team
;
3572 std::string team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM
);
3575 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3576 else if(g_team
== HORDE
)
3577 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3578 else if(g_team
== ALLIANCE
)
3579 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST
, g_id
,team_name
.c_str(),player
->GetZoneId());
3585 std::string team_name
;
3588 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ANY
);
3589 else if(g_team
== HORDE
)
3590 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE
);
3591 else if(g_team
== ALLIANCE
)
3592 team_name
= GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE
);
3594 if(g_team
== ~uint32(0))
3595 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS
, player
->GetZoneId());
3597 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION
, player
->GetZoneId(),team_name
.c_str());
3604 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args
)
3606 uint32 emote
= atoi((char*)args
);
3608 Creature
* target
= getSelectedCreature();
3611 SendSysMessage(LANG_SELECT_CREATURE
);
3612 SetSentErrorMessage(true);
3616 target
->SetUInt32Value(UNIT_NPC_EMOTESTATE
,emote
);
3621 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3623 Creature
* target
= getSelectedCreature();
3627 SendSysMessage(LANG_SELECT_CREATURE
);
3628 SetSentErrorMessage(true);
3632 uint32 faction
= target
->getFaction();
3633 uint32 npcflags
= target
->GetUInt32Value(UNIT_NPC_FLAGS
);
3634 uint32 displayid
= target
->GetDisplayId();
3635 uint32 nativeid
= target
->GetNativeDisplayId();
3636 uint32 Entry
= target
->GetEntry();
3637 CreatureInfo
const* cInfo
= target
->GetCreatureInfo();
3639 int32 curRespawnDelay
= target
->GetRespawnTimeEx()-time(NULL
);
3640 if(curRespawnDelay
< 0)
3641 curRespawnDelay
= 0;
3642 std::string curRespawnDelayStr
= secsToTimeString(curRespawnDelay
,true);
3643 std::string defRespawnDelayStr
= secsToTimeString(target
->GetRespawnDelay(),true);
3645 PSendSysMessage(LANG_NPCINFO_CHAR
, target
->GetDBTableGUIDLow(), faction
, npcflags
, Entry
, displayid
, nativeid
);
3646 PSendSysMessage(LANG_NPCINFO_LEVEL
, target
->getLevel());
3647 PSendSysMessage(LANG_NPCINFO_HEALTH
,target
->GetCreateHealth(), target
->GetMaxHealth(), target
->GetHealth());
3648 PSendSysMessage(LANG_NPCINFO_FLAGS
, target
->GetUInt32Value(UNIT_FIELD_FLAGS
), target
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
), target
->getFaction());
3649 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES
, defRespawnDelayStr
.c_str(),curRespawnDelayStr
.c_str());
3650 PSendSysMessage(LANG_NPCINFO_LOOT
, cInfo
->lootid
,cInfo
->pickpocketLootId
,cInfo
->SkinLootId
);
3651 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID
, target
->GetInstanceId());
3652 PSendSysMessage(LANG_NPCINFO_POSITION
,float(target
->GetPositionX()), float(target
->GetPositionY()), float(target
->GetPositionZ()));
3654 if ((npcflags
& UNIT_NPC_FLAG_VENDOR
) )
3656 SendSysMessage(LANG_NPCINFO_VENDOR
);
3658 if ((npcflags
& UNIT_NPC_FLAG_TRAINER
) )
3660 SendSysMessage(LANG_NPCINFO_TRAINER
);
3666 bool ChatHandler::HandleExploreCheatCommand(const char* args
)
3671 int flag
= atoi((char*)args
);
3673 Player
*chr
= getSelectedPlayer();
3676 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3677 SetSentErrorMessage(true);
3683 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL
, chr
->GetName());
3684 if (needReportToTarget(chr
))
3685 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL
,GetName());
3689 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING
, chr
->GetName());
3690 if (needReportToTarget(chr
))
3691 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING
,GetName());
3694 for (uint8 i
=0; i
<128; i
++)
3698 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0xFFFFFFFF);
3702 m_session
->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1
+i
,0);
3709 bool ChatHandler::HandleHoverCommand(const char* args
)
3711 char* px
= strtok((char*)args
, " ");
3718 m_session
->GetPlayer()->SetHover(flag
);
3721 SendSysMessage(LANG_HOVER_ENABLED
);
3723 SendSysMessage(LANG_HOVER_DISABLED
);
3728 bool ChatHandler::HandleLevelUpCommand(const char* args
)
3730 char* px
= strtok((char*)args
, " ");
3731 char* py
= strtok((char*)NULL
, " ");
3733 // command format parsing
3734 char* pname
= (char*)NULL
;
3737 if(px
&& py
) // .levelup name level
3739 addlevel
= atoi(py
);
3742 else if(px
&& !py
) // .levelup name OR .levelup level
3744 if(isalpha(px
[0])) // .levelup name
3746 else // .levelup level
3747 addlevel
= atoi(px
);
3749 // else .levelup - nothing do for preparing
3753 uint64 chr_guid
= 0;
3757 if(pname
) // player by name
3760 if(!normalizePlayerName(name
))
3762 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3763 SetSentErrorMessage(true);
3767 chr
= objmgr
.GetPlayer(name
.c_str());
3768 if(!chr
) // not in game
3770 chr_guid
= objmgr
.GetPlayerGUIDByName(name
);
3773 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
3774 SetSentErrorMessage(true);
3779 else // player by selection
3781 chr
= getSelectedPlayer();
3785 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3786 SetSentErrorMessage(true);
3790 name
= chr
->GetName();
3793 assert(chr
|| chr_guid
);
3795 int32 oldlevel
= chr
? chr
->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL
,chr_guid
);
3796 int32 newlevel
= oldlevel
+ addlevel
;
3799 if(newlevel
> 255) // hardcoded maximum level
3804 chr
->GiveLevel(newlevel
);
3805 chr
->InitTalentForLevel();
3806 chr
->SetUInt32Value(PLAYER_XP
,0);
3808 if(oldlevel
== newlevel
)
3809 ChatHandler(chr
).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET
);
3811 if(oldlevel
< newlevel
)
3812 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_UP
,newlevel
-oldlevel
);
3814 if(oldlevel
> newlevel
)
3815 ChatHandler(chr
).PSendSysMessage(LANG_YOURS_LEVEL_DOWN
,newlevel
-oldlevel
);
3819 // update level and XP at level, all other will be updated at loading
3821 Player::LoadValuesArrayFromDB(values
,chr_guid
);
3822 Player::SetUInt32ValueInArray(values
,UNIT_FIELD_LEVEL
,newlevel
);
3823 Player::SetUInt32ValueInArray(values
,PLAYER_XP
,0);
3824 Player::SaveValuesArrayInDB(values
,chr_guid
);
3827 if(m_session
->GetPlayer() != chr
) // including chr==NULL
3828 PSendSysMessage(LANG_YOU_CHANGE_LVL
,name
.c_str(),newlevel
);
3832 bool ChatHandler::HandleShowAreaCommand(const char* args
)
3837 int area
= atoi((char*)args
);
3839 Player
*chr
= getSelectedPlayer();
3842 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3843 SetSentErrorMessage(true);
3847 int offset
= area
/ 32;
3848 uint32 val
= (uint32
)(1 << (area
% 32));
3852 SendSysMessage(LANG_BAD_VALUE
);
3853 SetSentErrorMessage(true);
3857 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3858 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
| val
));
3860 SendSysMessage(LANG_EXPLORE_AREA
);
3864 bool ChatHandler::HandleHideAreaCommand(const char* args
)
3869 int area
= atoi((char*)args
);
3871 Player
*chr
= getSelectedPlayer();
3874 SendSysMessage(LANG_NO_CHAR_SELECTED
);
3875 SetSentErrorMessage(true);
3879 int offset
= area
/ 32;
3880 uint32 val
= (uint32
)(1 << (area
% 32));
3884 SendSysMessage(LANG_BAD_VALUE
);
3885 SetSentErrorMessage(true);
3889 uint32 currFields
= chr
->GetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
);
3890 chr
->SetUInt32Value(PLAYER_EXPLORED_ZONES_1
+ offset
, (uint32
)(currFields
^ val
));
3892 SendSysMessage(LANG_UNEXPLORE_AREA
);
3896 bool ChatHandler::HandleUpdate(const char* args
)
3904 char* pUpdateIndex
= strtok((char*)args
, " ");
3906 Unit
* chr
= getSelectedUnit();
3909 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
3910 SetSentErrorMessage(true);
3918 updateIndex
= atoi(pUpdateIndex
);
3920 if(chr
->GetTypeId() == TYPEID_PLAYER
)
3922 if (updateIndex
>=PLAYER_END
) return true;
3926 if (updateIndex
>=UNIT_END
) return true;
3929 char* pvalue
= strtok(NULL
, " ");
3932 value
=chr
->GetUInt32Value(updateIndex
);
3934 PSendSysMessage(LANG_UPDATE
, chr
->GetGUIDLow(),updateIndex
,value
);
3940 PSendSysMessage(LANG_UPDATE_CHANGE
, chr
->GetGUIDLow(),updateIndex
,value
);
3942 chr
->SetUInt32Value(updateIndex
,value
);
3947 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3949 m_session
->SendShowBank( m_session
->GetPlayer()->GetGUID() );
3954 bool ChatHandler::HandleChangeWeather(const char* args
)
3960 if (!sWorld
.getConfig(CONFIG_WEATHER
))
3962 SendSysMessage(LANG_WEATHER_DISABLED
);
3963 SetSentErrorMessage(true);
3967 //*Change the weather of a cell
3968 char* px
= strtok((char*)args
, " ");
3969 char* py
= strtok(NULL
, " ");
3974 uint32 type
= (uint32
)atoi(px
); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3975 float grade
= (float)atof(py
); //0 to 1, sending -1 is instand good weather
3977 Player
*player
= m_session
->GetPlayer();
3978 uint32 zoneid
= player
->GetZoneId();
3980 Weather
* wth
= sWorld
.FindWeather(zoneid
);
3983 wth
= sWorld
.AddWeather(zoneid
);
3986 SendSysMessage(LANG_NO_WEATHER
);
3987 SetSentErrorMessage(true);
3991 wth
->SetWeather(WeatherType(type
), grade
);
3996 bool ChatHandler::HandleSetValue(const char* args
)
4001 char* px
= strtok((char*)args
, " ");
4002 char* py
= strtok(NULL
, " ");
4003 char* pz
= strtok(NULL
, " ");
4008 Unit
* target
= getSelectedUnit();
4011 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4012 SetSentErrorMessage(true);
4016 uint64 guid
= target
->GetGUID();
4018 uint32 Opcode
= (uint32
)atoi(px
);
4019 if(Opcode
>= target
->GetValuesCount())
4021 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4026 bool isint32
= true;
4028 isint32
= (bool)atoi(pz
);
4031 iValue
= (uint32
)atoi(py
);
4032 sLog
.outDebug(GetMangosString(LANG_SET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4033 target
->SetUInt32Value( Opcode
, iValue
);
4034 PSendSysMessage(LANG_SET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
,iValue
);
4038 fValue
= (float)atof(py
);
4039 sLog
.outDebug(GetMangosString(LANG_SET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4040 target
->SetFloatValue( Opcode
, fValue
);
4041 PSendSysMessage(LANG_SET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
,fValue
);
4047 bool ChatHandler::HandleGetValue(const char* args
)
4052 char* px
= strtok((char*)args
, " ");
4053 char* pz
= strtok(NULL
, " ");
4058 Unit
* target
= getSelectedUnit();
4061 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4062 SetSentErrorMessage(true);
4066 uint64 guid
= target
->GetGUID();
4068 uint32 Opcode
= (uint32
)atoi(px
);
4069 if(Opcode
>= target
->GetValuesCount())
4071 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, GUID_LOPART(guid
), target
->GetValuesCount());
4076 bool isint32
= true;
4078 isint32
= (bool)atoi(pz
);
4082 iValue
= target
->GetUInt32Value( Opcode
);
4083 sLog
.outDebug(GetMangosString(LANG_GET_UINT
), GUID_LOPART(guid
), Opcode
, iValue
);
4084 PSendSysMessage(LANG_GET_UINT_FIELD
, GUID_LOPART(guid
), Opcode
, iValue
);
4088 fValue
= target
->GetFloatValue( Opcode
);
4089 sLog
.outDebug(GetMangosString(LANG_GET_FLOAT
), GUID_LOPART(guid
), Opcode
, fValue
);
4090 PSendSysMessage(LANG_GET_FLOAT_FIELD
, GUID_LOPART(guid
), Opcode
, fValue
);
4096 bool ChatHandler::HandleSet32Bit(const char* args
)
4101 char* px
= strtok((char*)args
, " ");
4102 char* py
= strtok(NULL
, " ");
4107 uint32 Opcode
= (uint32
)atoi(px
);
4108 uint32 Value
= (uint32
)atoi(py
);
4109 if (Value
> 32) //uint32 = 32 bits
4112 sLog
.outDebug(GetMangosString(LANG_SET_32BIT
), Opcode
, Value
);
4114 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, 2^Value
);
4116 PSendSysMessage(LANG_SET_32BIT_FIELD
, Opcode
,1);
4120 bool ChatHandler::HandleMod32Value(const char* args
)
4125 char* px
= strtok((char*)args
, " ");
4126 char* py
= strtok(NULL
, " ");
4131 uint32 Opcode
= (uint32
)atoi(px
);
4132 int Value
= atoi(py
);
4134 if(Opcode
>= m_session
->GetPlayer()->GetValuesCount())
4136 PSendSysMessage(LANG_TOO_BIG_INDEX
, Opcode
, m_session
->GetPlayer()->GetGUIDLow(), m_session
->GetPlayer( )->GetValuesCount());
4140 sLog
.outDebug(GetMangosString(LANG_CHANGE_32BIT
), Opcode
, Value
);
4142 int CurrentValue
= (int)m_session
->GetPlayer( )->GetUInt32Value( Opcode
);
4144 CurrentValue
+= Value
;
4145 m_session
->GetPlayer( )->SetUInt32Value( Opcode
, (uint32
)CurrentValue
);
4147 PSendSysMessage(LANG_CHANGE_32BIT_FIELD
, Opcode
,CurrentValue
);
4152 bool ChatHandler::HandleAddTeleCommand(const char * args
)
4157 Player
*player
=m_session
->GetPlayer();
4161 std::string name
= args
;
4163 if(objmgr
.GetGameTele(name
))
4165 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST
);
4166 SetSentErrorMessage(true);
4171 tele
.position_x
= player
->GetPositionX();
4172 tele
.position_y
= player
->GetPositionY();
4173 tele
.position_z
= player
->GetPositionZ();
4174 tele
.orientation
= player
->GetOrientation();
4175 tele
.mapId
= player
->GetMapId();
4178 if(objmgr
.AddGameTele(tele
))
4180 SendSysMessage(LANG_COMMAND_TP_ADDED
);
4184 SendSysMessage(LANG_COMMAND_TP_ADDEDERR
);
4185 SetSentErrorMessage(true);
4192 bool ChatHandler::HandleDelTeleCommand(const char * args
)
4197 std::string name
= args
;
4199 if(!objmgr
.DeleteGameTele(name
))
4201 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
4202 SetSentErrorMessage(true);
4206 SendSysMessage(LANG_COMMAND_TP_DELETED
);
4210 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4212 Unit
*unit
= getSelectedUnit();
4215 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
4216 SetSentErrorMessage(true);
4220 char const* talentStr
= GetMangosString(LANG_TALENT
);
4221 char const* passiveStr
= GetMangosString(LANG_PASSIVE
);
4223 Unit::AuraMap
const& uAuras
= unit
->GetAuras();
4224 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS
, uAuras
.size());
4225 for (Unit::AuraMap::const_iterator itr
= uAuras
.begin(); itr
!= uAuras
.end(); ++itr
)
4227 bool talent
= GetTalentSpellCost(itr
->second
->GetId()) > 0;
4228 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL
, itr
->second
->GetId(), itr
->second
->GetEffIndex(),
4229 itr
->second
->GetModifier()->m_auraname
, itr
->second
->GetAuraDuration(), itr
->second
->GetAuraMaxDuration(),
4230 itr
->second
->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],
4231 (itr
->second
->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4232 IS_PLAYER_GUID(itr
->second
->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr
->second
->GetCasterGUID()));
4234 for (int i
= 0; i
< TOTAL_AURAS
; i
++)
4236 Unit::AuraList
const& uAuraList
= unit
->GetAurasByType(AuraType(i
));
4237 if (uAuraList
.empty()) continue;
4238 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE
, uAuraList
.size(), i
);
4239 for (Unit::AuraList::const_iterator itr
= uAuraList
.begin(); itr
!= uAuraList
.end(); ++itr
)
4241 bool talent
= GetTalentSpellCost((*itr
)->GetId()) > 0;
4242 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE
, (*itr
)->GetId(), (*itr
)->GetEffIndex(),
4243 (*itr
)->GetSpellProto()->SpellName
[m_session
->GetSessionDbcLocale()],((*itr
)->IsPassive() ? passiveStr
: ""),(talent
? talentStr
: ""),
4244 IS_PLAYER_GUID((*itr
)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr
)->GetCasterGUID()));
4250 bool ChatHandler::HandleResetHonorCommand (const char * args
)
4252 char* pName
= strtok((char*)args
, "");
4253 Player
*player
= NULL
;
4256 std::string name
= pName
;
4257 if(!normalizePlayerName(name
))
4259 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4260 SetSentErrorMessage(true);
4264 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4265 player
= objmgr
.GetPlayer(guid
);
4268 player
= getSelectedPlayer();
4272 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4276 player
->SetUInt32Value(PLAYER_FIELD_KILLS
, 0);
4277 player
->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS
, 0);
4278 player
->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY
, 0);
4279 player
->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION
, 0);
4280 player
->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION
, 0);
4285 static bool HandleResetStatsOrLevelHelper(Player
* player
)
4287 PlayerInfo
const *info
= objmgr
.GetPlayerInfo(player
->getRace(), player
->getClass());
4288 if(!info
) return false;
4290 ChrClassesEntry
const* cEntry
= sChrClassesStore
.LookupEntry(player
->getClass());
4293 sLog
.outError("Class %u not found in DBC (Wrong DBC files?)",player
->getClass());
4297 uint8 powertype
= cEntry
->powerType
;
4300 if(powertype
== POWER_RAGE
)
4301 unitfield
= 0x1100EE00;
4302 else if(powertype
== POWER_ENERGY
)
4303 unitfield
= 0x00000000;
4304 else if(powertype
== POWER_MANA
)
4305 unitfield
= 0x0000EE00;
4308 sLog
.outError("Invalid default powertype %u for player (class %u)",powertype
,player
->getClass());
4312 // reset m_form if no aura
4313 if(!player
->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT
))
4314 player
->m_form
= FORM_NONE
;
4316 player
->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS
, DEFAULT_WORLD_OBJECT_SIZE
);
4317 player
->SetFloatValue(UNIT_FIELD_COMBATREACH
, 1.5f
);
4319 player
->setFactionForRace(player
->getRace());
4321 player
->SetUInt32Value(UNIT_FIELD_BYTES_0
, ( ( player
->getRace() ) | ( player
->getClass() << 8 ) | ( player
->getGender() << 16 ) | ( powertype
<< 24 ) ) );
4323 // reset only if player not in some form;
4324 if(player
->m_form
==FORM_NONE
)
4326 switch(player
->getGender())
4329 player
->SetDisplayId(info
->displayId_f
);
4330 player
->SetNativeDisplayId(info
->displayId_f
);
4333 player
->SetDisplayId(info
->displayId_m
);
4334 player
->SetNativeDisplayId(info
->displayId_m
);
4341 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4342 player
->SetUInt32Value(UNIT_FIELD_BYTES_1
, unitfield
);
4343 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 1, UNIT_BYTE2_FLAG_UNK3
| UNIT_BYTE2_FLAG_UNK5
);
4344 player
->SetByteValue(UNIT_FIELD_BYTES_2
, 3, player
->m_form
);
4346 player
->SetUInt32Value(UNIT_FIELD_FLAGS
, UNIT_FLAG_PVP_ATTACKABLE
);
4348 //-1 is default value
4349 player
->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX
, uint32(-1));
4351 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4355 bool ChatHandler::HandleResetLevelCommand(const char * args
)
4357 char* pName
= strtok((char*)args
, "");
4358 Player
*player
= NULL
;
4361 std::string name
= pName
;
4362 if(!normalizePlayerName(name
))
4364 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4365 SetSentErrorMessage(true);
4369 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4370 player
= objmgr
.GetPlayer(guid
);
4373 player
= getSelectedPlayer();
4377 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4378 SetSentErrorMessage(true);
4382 if(!HandleResetStatsOrLevelHelper(player
))
4385 player
->SetLevel(1);
4386 player
->InitStatsForLevel(true);
4387 player
->InitTaxiNodesForLevel();
4388 player
->InitTalentForLevel();
4389 player
->SetUInt32Value(PLAYER_XP
,0);
4391 // reset level to summoned pet
4392 Pet
* pet
= player
->GetPet();
4393 if(pet
&& pet
->getPetType()==SUMMON_PET
)
4394 pet
->InitStatsForLevel(1);
4399 bool ChatHandler::HandleResetStatsCommand(const char * args
)
4401 char* pName
= strtok((char*)args
, "");
4402 Player
*player
= NULL
;
4405 std::string name
= pName
;
4406 if(!normalizePlayerName(name
))
4408 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4409 SetSentErrorMessage(true);
4413 uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4414 player
= objmgr
.GetPlayer(guid
);
4417 player
= getSelectedPlayer();
4421 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4422 SetSentErrorMessage(true);
4426 if(!HandleResetStatsOrLevelHelper(player
))
4429 player
->InitStatsForLevel(true);
4430 player
->InitTaxiNodesForLevel();
4431 player
->InitTalentForLevel();
4436 bool ChatHandler::HandleResetSpellsCommand(const char * args
)
4438 char* pName
= strtok((char*)args
, "");
4439 Player
*player
= NULL
;
4440 uint64 playerGUID
= 0;
4443 std::string name
= pName
;
4445 if(!normalizePlayerName(name
))
4447 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4448 SetSentErrorMessage(true);
4452 player
= objmgr
.GetPlayer(name
.c_str());
4454 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4457 player
= getSelectedPlayer();
4459 if(!player
&& !playerGUID
)
4461 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4462 SetSentErrorMessage(true);
4468 player
->resetSpells();
4470 ChatHandler(player
).SendSysMessage(LANG_RESET_SPELLS
);
4472 if(m_session
->GetPlayer()!=player
)
4473 PSendSysMessage(LANG_RESET_SPELLS_ONLINE
,player
->GetName());
4477 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS
), GUID_LOPART(playerGUID
));
4478 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE
,pName
);
4484 bool ChatHandler::HandleResetTalentsCommand(const char * args
)
4486 char* pName
= strtok((char*)args
, "");
4487 Player
*player
= NULL
;
4488 uint64 playerGUID
= 0;
4491 std::string name
= pName
;
4492 if(!normalizePlayerName(name
))
4494 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4495 SetSentErrorMessage(true);
4499 player
= objmgr
.GetPlayer(name
.c_str());
4501 playerGUID
= objmgr
.GetPlayerGUIDByName(name
.c_str());
4504 player
= getSelectedPlayer();
4506 if(!player
&& !playerGUID
)
4508 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4509 SetSentErrorMessage(true);
4515 player
->resetTalents(true);
4517 ChatHandler(player
).SendSysMessage(LANG_RESET_TALENTS
);
4519 if(m_session
->GetPlayer()!=player
)
4520 PSendSysMessage(LANG_RESET_TALENTS_ONLINE
,player
->GetName());
4524 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS
), GUID_LOPART(playerGUID
) );
4525 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE
,pName
);
4531 bool ChatHandler::HandleResetAllCommand(const char * args
)
4536 std::string casename
= args
;
4538 AtLoginFlags atLogin
;
4540 // Command specially created as single command to prevent using short case names
4541 if(casename
=="spells")
4543 atLogin
= AT_LOGIN_RESET_SPELLS
;
4544 sWorld
.SendWorldText(LANG_RESETALL_SPELLS
);
4546 else if(casename
=="talents")
4548 atLogin
= AT_LOGIN_RESET_TALENTS
;
4549 sWorld
.SendWorldText(LANG_RESETALL_TALENTS
);
4553 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE
,args
);
4554 SetSentErrorMessage(true);
4558 CharacterDatabase
.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin
);
4559 HashMapHolder
<Player
>::MapType
const& plist
= ObjectAccessor::Instance().GetPlayers();
4560 for(HashMapHolder
<Player
>::MapType::const_iterator itr
= plist
.begin(); itr
!= plist
.end(); ++itr
)
4561 itr
->second
->SetAtLoginFlag(atLogin
);
4566 bool ChatHandler::HandleShutDownCommand(const char* args
)
4571 if(std::string(args
)=="cancel")
4573 sWorld
.ShutdownCancel();
4577 int32 time
= atoi(args
);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4583 sWorld
.ShutdownServ(time
);
4588 bool ChatHandler::HandleRestartCommand(const char* args
)
4593 if(std::string(args
)=="cancel")
4595 sWorld
.ShutdownCancel();
4599 int32 time
= atoi(args
);
4601 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4602 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4605 sWorld
.ShutdownServ(time
, SHUTDOWN_MASK_RESTART
);
4610 bool ChatHandler::HandleIdleRestartCommand(const char* args
)
4615 if(std::string(args
)=="cancel")
4617 sWorld
.ShutdownCancel();
4621 int32 time
= atoi(args
);
4623 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4624 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4627 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_RESTART
+SHUTDOWN_MASK_IDLE
);
4632 bool ChatHandler::HandleIdleShutDownCommand(const char* args
)
4637 if(std::string(args
)=="cancel")
4639 sWorld
.ShutdownCancel();
4643 int32 time
= atoi(args
);
4645 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4646 if(time
== 0 && (args
[0]!='0' || args
[1]!='\0') || time
< 0)
4649 sWorld
.ShutdownServ(time
,SHUTDOWN_MASK_IDLE
);
4654 bool ChatHandler::HandleAddQuest(const char* args
)
4656 Player
* player
= getSelectedPlayer();
4659 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4660 SetSentErrorMessage(true);
4664 // .addquest #entry'
4665 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4666 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4670 uint32 entry
= atol(cId
);
4672 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4676 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
,entry
);
4677 SetSentErrorMessage(true);
4681 // check item starting quest (it can work incorrectly if added without item in inventory)
4682 for (uint32 id
= 0; id
< sItemStorage
.MaxEntry
; id
++)
4684 ItemPrototype
const *pProto
= sItemStorage
.LookupEntry
<ItemPrototype
>(id
);
4688 if (pProto
->StartQuest
== entry
)
4690 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM
, entry
, pProto
->ItemId
);
4691 SetSentErrorMessage(true);
4696 // ok, normal (creature/GO starting) quest
4697 if( player
->CanAddQuest( pQuest
, true ) )
4699 player
->AddQuest( pQuest
, NULL
);
4701 if ( player
->CanCompleteQuest( entry
) )
4702 player
->CompleteQuest( entry
);
4708 bool ChatHandler::HandleRemoveQuest(const char* args
)
4710 Player
* player
= getSelectedPlayer();
4713 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4714 SetSentErrorMessage(true);
4718 // .removequest #entry'
4719 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4720 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4724 uint32 entry
= atol(cId
);
4726 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4730 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4731 SetSentErrorMessage(true);
4735 // remove all quest entries for 'entry' from quest log
4736 for(uint8 slot
= 0; slot
< MAX_QUEST_LOG_SIZE
; ++slot
)
4738 uint32 quest
= player
->GetQuestSlotQuestId(slot
);
4741 player
->SetQuestSlot(slot
,0);
4743 // we ignore unequippable quest items in this case, its' still be equipped
4744 player
->TakeQuestSourceItem( quest
, false );
4748 // set quest status to not started (will updated in DB at next save)
4749 player
->SetQuestStatus( entry
, QUEST_STATUS_NONE
);
4751 // reset rewarded for restart repeatable quest
4752 player
->getQuestStatusMap()[entry
].m_rewarded
= false;
4754 SendSysMessage(LANG_COMMAND_QUEST_REMOVED
);
4758 bool ChatHandler::HandleCompleteQuest(const char* args
)
4760 Player
* player
= getSelectedPlayer();
4763 SendSysMessage(LANG_NO_CHAR_SELECTED
);
4764 SetSentErrorMessage(true);
4768 // .quest complete #entry
4769 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4770 char* cId
= extractKeyFromLink((char*)args
,"Hquest");
4774 uint32 entry
= atol(cId
);
4776 Quest
const* pQuest
= objmgr
.GetQuestTemplate(entry
);
4778 // If player doesn't have the quest
4779 if(!pQuest
|| player
->GetQuestStatus(entry
) == QUEST_STATUS_NONE
)
4781 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND
, entry
);
4782 SetSentErrorMessage(true);
4786 // Add quest items for quests that require items
4787 for(uint8 x
= 0; x
< QUEST_OBJECTIVES_COUNT
; ++x
)
4789 uint32 id
= pQuest
->ReqItemId
[x
];
4790 uint32 count
= pQuest
->ReqItemCount
[x
];
4794 uint32 curItemCount
= player
->GetItemCount(id
,true);
4796 ItemPosCountVec dest
;
4797 uint8 msg
= player
->CanStoreNewItem( NULL_BAG
, NULL_SLOT
, dest
, id
, count
-curItemCount
);
4798 if( msg
== EQUIP_ERR_OK
)
4800 Item
* item
= player
->StoreNewItem( dest
, id
, true);
4801 player
->SendNewItem(item
,count
-curItemCount
,true,false);
4805 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4806 for(uint8 i
= 0; i
< QUEST_OBJECTIVES_COUNT
; i
++)
4808 uint32 creature
= pQuest
->ReqCreatureOrGOId
[i
];
4809 uint32 creaturecount
= pQuest
->ReqCreatureOrGOCount
[i
];
4811 if(uint32 spell_id
= pQuest
->ReqSpell
[i
])
4813 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4814 player
->CastedCreatureOrGO(creature
,0,spell_id
);
4816 else if(creature
> 0)
4818 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4819 player
->KilledMonster(creature
,0);
4821 else if(creature
< 0)
4823 for(uint16 z
= 0; z
< creaturecount
; ++z
)
4824 player
->CastedCreatureOrGO(creature
,0,0);
4828 // If the quest requires reputation to complete
4829 if(uint32 repFaction
= pQuest
->GetRepObjectiveFaction())
4831 uint32 repValue
= pQuest
->GetRepObjectiveValue();
4832 uint32 curRep
= player
->GetReputation(repFaction
);
4833 if(curRep
< repValue
)
4835 FactionEntry
const *factionEntry
= sFactionStore
.LookupEntry(repFaction
);
4836 player
->SetFactionReputation(factionEntry
,repValue
);
4840 // If the quest requires money
4841 int32 ReqOrRewMoney
= pQuest
->GetRewOrReqMoney();
4842 if(ReqOrRewMoney
< 0)
4843 player
->ModifyMoney(-ReqOrRewMoney
);
4845 player
->CompleteQuest(entry
);
4849 bool ChatHandler::HandleBanAccountCommand(const char* args
)
4851 return HandleBanHelper(BAN_ACCOUNT
,args
);
4854 bool ChatHandler::HandleBanCharacterCommand(const char* args
)
4856 return HandleBanHelper(BAN_CHARACTER
,args
);
4859 bool ChatHandler::HandleBanIPCommand(const char* args
)
4861 return HandleBanHelper(BAN_IP
,args
);
4864 bool ChatHandler::HandleBanHelper(BanMode mode
, const char* args
)
4869 char* cnameOrIP
= strtok ((char*)args
, " ");
4873 std::string nameOrIP
= cnameOrIP
;
4875 char* duration
= strtok (NULL
," ");
4876 if(!duration
|| !atoi(duration
))
4879 char* reason
= strtok (NULL
,"");
4886 if(!AccountMgr::normilizeString(nameOrIP
))
4888 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4889 SetSentErrorMessage(true);
4894 if(!normalizePlayerName(nameOrIP
))
4896 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4897 SetSentErrorMessage(true);
4902 if(!IsIPAddress(nameOrIP
.c_str()))
4907 switch(sWorld
.BanAccount(mode
, nameOrIP
, duration
, reason
,m_session
? m_session
->GetPlayerName() : ""))
4910 if(atoi(duration
)>0)
4911 PSendSysMessage(LANG_BAN_YOUBANNED
,nameOrIP
.c_str(),secsToTimeString(TimeStringToSecs(duration
),true).c_str(),reason
);
4913 PSendSysMessage(LANG_BAN_YOUPERMBANNED
,nameOrIP
.c_str(),reason
);
4915 case BAN_SYNTAX_ERROR
:
4921 PSendSysMessage(LANG_BAN_NOTFOUND
,"account",nameOrIP
.c_str());
4924 PSendSysMessage(LANG_BAN_NOTFOUND
,"character",nameOrIP
.c_str());
4927 PSendSysMessage(LANG_BAN_NOTFOUND
,"ip",nameOrIP
.c_str());
4930 SetSentErrorMessage(true);
4937 bool ChatHandler::HandleUnBanAccountCommand(const char* args
)
4939 return HandleUnBanHelper(BAN_ACCOUNT
,args
);
4942 bool ChatHandler::HandleUnBanCharacterCommand(const char* args
)
4944 return HandleUnBanHelper(BAN_CHARACTER
,args
);
4947 bool ChatHandler::HandleUnBanIPCommand(const char* args
)
4949 return HandleUnBanHelper(BAN_IP
,args
);
4952 bool ChatHandler::HandleUnBanHelper(BanMode mode
, const char* args
)
4957 char* cnameOrIP
= strtok ((char*)args
, " ");
4961 std::string nameOrIP
= cnameOrIP
;
4966 if(!AccountMgr::normilizeString(nameOrIP
))
4968 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,nameOrIP
.c_str());
4969 SetSentErrorMessage(true);
4974 if(!normalizePlayerName(nameOrIP
))
4976 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
4977 SetSentErrorMessage(true);
4982 if(!IsIPAddress(nameOrIP
.c_str()))
4987 if(sWorld
.RemoveBanAccount(mode
,nameOrIP
))
4988 PSendSysMessage(LANG_UNBAN_UNBANNED
,nameOrIP
.c_str());
4990 PSendSysMessage(LANG_UNBAN_ERROR
,nameOrIP
.c_str());
4995 bool ChatHandler::HandleBanInfoAccountCommand(const char* args
)
5000 char* cname
= strtok((char*)args
, "");
5004 std::string account_name
= cname
;
5005 if(!AccountMgr::normilizeString(account_name
))
5007 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5008 SetSentErrorMessage(true);
5012 uint32 accountid
= accmgr
.GetId(account_name
);
5015 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5019 return HandleBanInfoHelper(accountid
,account_name
.c_str());
5022 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args
)
5027 char* cname
= strtok ((char*)args
, "");
5031 std::string name
= cname
;
5032 if(!normalizePlayerName(name
))
5034 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5035 SetSentErrorMessage(true);
5039 uint32 accountid
= objmgr
.GetPlayerAccountIdByPlayerName(name
);
5042 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
5043 SetSentErrorMessage(true);
5047 std::string accountname
;
5048 if(!accmgr
.GetName(accountid
,accountname
))
5050 PSendSysMessage(LANG_BANINFO_NOCHARACTER
);
5054 return HandleBanInfoHelper(accountid
,accountname
.c_str());
5057 bool ChatHandler::HandleBanInfoHelper(uint32 accountid
, char const* accountname
)
5059 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
);
5062 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN
, accountname
);
5066 PSendSysMessage(LANG_BANINFO_BANHISTORY
,accountname
);
5069 Field
* fields
= result
->Fetch();
5071 time_t unbandate
= time_t(fields
[3].GetUInt64());
5072 bool active
= false;
5073 if(fields
[2].GetBool() && (fields
[1].GetUInt64() == (uint64
)0 ||unbandate
>= time(NULL
)) )
5075 bool permanent
= (fields
[1].GetUInt64() == (uint64
)0);
5076 std::string bantime
= permanent
?GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[1].GetUInt64(), true);
5077 PSendSysMessage(LANG_BANINFO_HISTORYENTRY
,
5078 fields
[0].GetString(), bantime
.c_str(), active
? GetMangosString(LANG_BANINFO_YES
):GetMangosString(LANG_BANINFO_NO
), fields
[4].GetString(), fields
[5].GetString());
5079 }while (result
->NextRow());
5085 bool ChatHandler::HandleBanInfoIPCommand(const char* args
)
5090 char* cIP
= strtok ((char*)args
, "");
5094 if (!IsIPAddress(cIP
))
5097 std::string IP
= cIP
;
5099 loginDatabase
.escape_string(IP
);
5100 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());
5103 PSendSysMessage(LANG_BANINFO_NOIP
);
5107 Field
*fields
= result
->Fetch();
5108 bool permanent
= !fields
[6].GetUInt64();
5109 PSendSysMessage(LANG_BANINFO_IPENTRY
,
5110 fields
[0].GetString(), fields
[1].GetString(), permanent
? GetMangosString(LANG_BANINFO_NEVER
):fields
[2].GetString(),
5111 permanent
? GetMangosString(LANG_BANINFO_INFINITE
):secsToTimeString(fields
[3].GetUInt64(), true).c_str(), fields
[4].GetString(), fields
[5].GetString());
5116 bool ChatHandler::HandleBanListCharacterCommand(const char* args
)
5118 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5120 char* cFilter
= strtok ((char*)args
, " ");
5124 std::string filter
= cFilter
;
5125 loginDatabase
.escape_string(filter
);
5126 QueryResult
* result
= CharacterDatabase
.PQuery("SELECT account FROM characters WHERE name "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'"),filter
.c_str());
5129 PSendSysMessage(LANG_BANLIST_NOCHARACTER
);
5133 return HandleBanListHelper(result
);
5136 bool ChatHandler::HandleBanListAccountCommand(const char* args
)
5138 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5140 char* cFilter
= strtok((char*)args
, " ");
5141 std::string filter
= cFilter
? cFilter
: "";
5142 loginDatabase
.escape_string(filter
);
5144 QueryResult
* result
;
5148 result
= loginDatabase
.Query("SELECT account.id, username FROM account, account_banned"
5149 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5153 result
= loginDatabase
.PQuery("SELECT account.id, username FROM account, account_banned"
5154 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5160 PSendSysMessage(LANG_BANLIST_NOACCOUNT
);
5164 return HandleBanListHelper(result
);
5167 bool ChatHandler::HandleBanListHelper(QueryResult
* result
)
5169 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT
);
5171 // Chat short output
5176 Field
* fields
= result
->Fetch();
5177 uint32 accountid
= fields
[0].GetUInt32();
5179 QueryResult
* banresult
= loginDatabase
.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid
);
5182 Field
* fields2
= banresult
->Fetch();
5183 PSendSysMessage("%s",fields2
[0].GetString());
5186 } while (result
->NextRow());
5188 // Console wide output
5191 SendSysMessage(LANG_BANLIST_ACCOUNTS
);
5192 SendSysMessage("===============================================================================");
5193 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER
);
5196 SendSysMessage("-------------------------------------------------------------------------------");
5197 Field
*fields
= result
->Fetch();
5198 uint32 account_id
= fields
[0].GetUInt32 ();
5200 std::string account_name
;
5202 // "account" case, name can be get in same query
5203 if(result
->GetFieldCount() > 1)
5204 account_name
= fields
[1].GetCppString();
5205 // "character" case, name need extract from another DB
5207 accmgr
.GetName (account_id
,account_name
);
5209 // No SQL injection. id is uint32.
5210 QueryResult
*banInfo
= loginDatabase
.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id
);
5213 Field
*fields2
= banInfo
->Fetch();
5216 time_t t_ban
= fields2
[0].GetUInt64();
5217 tm
* aTm_ban
= localtime(&t_ban
);
5219 if (fields2
[0].GetUInt64() == fields2
[1].GetUInt64())
5221 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5222 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
,
5223 fields2
[2].GetString(),fields2
[3].GetString());
5227 time_t t_unban
= fields2
[1].GetUInt64();
5228 tm
* aTm_unban
= localtime(&t_unban
);
5229 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5230 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
,
5231 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5232 fields2
[2].GetString(),fields2
[3].GetString());
5234 }while ( banInfo
->NextRow() );
5237 }while( result
->NextRow() );
5238 SendSysMessage("===============================================================================");
5245 bool ChatHandler::HandleBanListIPCommand(const char* args
)
5247 loginDatabase
.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5249 char* cFilter
= strtok((char*)args
, " ");
5250 std::string filter
= cFilter
? cFilter
: "";
5251 loginDatabase
.escape_string(filter
);
5253 QueryResult
* result
;
5257 result
= loginDatabase
.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5258 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5259 " ORDER BY unbandate" );
5263 result
= loginDatabase
.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5264 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_
" "_CONCAT3_("'%%'","'%s'","'%%'")
5265 " ORDER BY unbandate",filter
.c_str() );
5270 PSendSysMessage(LANG_BANLIST_NOIP
);
5274 PSendSysMessage(LANG_BANLIST_MATCHINGIP
);
5275 // Chat short output
5280 Field
* fields
= result
->Fetch();
5281 PSendSysMessage("%s",fields
[0].GetString());
5282 } while (result
->NextRow());
5284 // Console wide output
5287 SendSysMessage(LANG_BANLIST_IPS
);
5288 SendSysMessage("===============================================================================");
5289 SendSysMessage(LANG_BANLIST_IPS_HEADER
);
5292 SendSysMessage("-------------------------------------------------------------------------------");
5293 Field
*fields
= result
->Fetch();
5294 time_t t_ban
= fields
[1].GetUInt64();
5295 tm
* aTm_ban
= localtime(&t_ban
);
5296 if ( fields
[1].GetUInt64() == fields
[2].GetUInt64() )
5298 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5299 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
,
5300 fields
[3].GetString(), fields
[4].GetString());
5304 time_t t_unban
= fields
[2].GetUInt64();
5305 tm
* aTm_unban
= localtime(&t_unban
);
5306 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5307 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
,
5308 aTm_unban
->tm_year
%100, aTm_unban
->tm_mon
+1, aTm_unban
->tm_mday
, aTm_unban
->tm_hour
, aTm_unban
->tm_min
,
5309 fields
[3].GetString(), fields
[4].GetString());
5311 }while( result
->NextRow() );
5312 SendSysMessage("===============================================================================");
5319 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5321 Player
* pl
= m_session
->GetPlayer();
5323 // accept only explicitly selected target (not implicitly self targeting case)
5324 Unit
* target
= getSelectedUnit();
5325 if(pl
->GetSelection() && target
)
5327 if(target
->GetTypeId()!=TYPEID_UNIT
)
5329 SendSysMessage(LANG_SELECT_CREATURE
);
5330 SetSentErrorMessage(true);
5334 if(target
->isDead())
5335 ((Creature
*)target
)->Respawn();
5339 CellPair
p(MaNGOS::ComputeCellPair(pl
->GetPositionX(), pl
->GetPositionY()));
5341 cell
.data
.Part
.reserved
= ALL_DISTRICT
;
5344 MaNGOS::RespawnDo u_do
;
5345 MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
> worker(u_do
);
5347 TypeContainerVisitor
<MaNGOS::WorldObjectWorker
<MaNGOS::RespawnDo
>, GridTypeMapContainer
> obj_worker(worker
);
5348 CellLock
<GridReadGuard
> cell_lock(cell
, p
);
5349 cell_lock
->Visit(cell_lock
, obj_worker
, *MapManager::Instance().GetMap(pl
->GetMapId(), pl
));
5354 bool ChatHandler::HandleFlyModeCommand(const char* args
)
5359 Unit
*unit
= getSelectedUnit();
5360 if (!unit
|| (unit
->GetTypeId() != TYPEID_PLAYER
))
5361 unit
= m_session
->GetPlayer();
5363 WorldPacket
data(12);
5364 if (strncmp(args
, "on", 3) == 0)
5365 data
.SetOpcode(SMSG_MOVE_SET_CAN_FLY
);
5366 else if (strncmp(args
, "off", 4) == 0)
5367 data
.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY
);
5370 SendSysMessage(LANG_USE_BOL
);
5373 data
.append(unit
->GetPackGUID());
5374 data
<< uint32(0); // unknown
5375 unit
->SendMessageToSet(&data
, true);
5376 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS
, unit
->GetName(), args
);
5380 bool ChatHandler::HandleLoadPDumpCommand(const char *args
)
5385 char * file
= strtok((char*)args
, " ");
5389 char * account
= strtok(NULL
, " ");
5393 std::string account_name
= account
;
5394 if(!AccountMgr::normilizeString(account_name
))
5396 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5397 SetSentErrorMessage(true);
5401 uint32 account_id
= accmgr
.GetId(account_name
);
5404 account_id
= atoi(account
); // use original string
5407 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5408 SetSentErrorMessage(true);
5413 if(!accmgr
.GetName(account_id
,account_name
))
5415 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
5416 SetSentErrorMessage(true);
5420 char* guid_str
= NULL
;
5421 char* name_str
= strtok(NULL
, " ");
5427 // normalize the name if specified and check if it exists
5428 if(!normalizePlayerName(name
))
5430 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5431 SetSentErrorMessage(true);
5435 if(!ObjectMgr::IsValidName(name
,true))
5437 PSendSysMessage(LANG_INVALID_CHARACTER_NAME
);
5438 SetSentErrorMessage(true);
5442 guid_str
= strtok(NULL
, " ");
5449 guid
= atoi(guid_str
);
5452 PSendSysMessage(LANG_INVALID_CHARACTER_GUID
);
5453 SetSentErrorMessage(true);
5457 if(objmgr
.GetPlayerAccountIdByGUID(guid
))
5459 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE
,guid
);
5460 SetSentErrorMessage(true);
5465 switch(PlayerDumpReader().LoadDump(file
, account_id
, name
, guid
))
5468 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS
);
5470 case DUMP_FILE_OPEN_ERROR
:
5471 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5472 SetSentErrorMessage(true);
5474 case DUMP_FILE_BROKEN
:
5475 PSendSysMessage(LANG_DUMP_BROKEN
,file
);
5476 SetSentErrorMessage(true);
5478 case DUMP_TOO_MANY_CHARS
:
5479 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL
,account_name
.c_str(),account_id
);
5480 SetSentErrorMessage(true);
5483 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED
);
5484 SetSentErrorMessage(true);
5491 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args
)
5496 uint32 newEntryNum
= atoi(args
);
5500 Unit
* unit
= getSelectedUnit();
5501 if(!unit
|| unit
->GetTypeId() != TYPEID_UNIT
)
5503 SendSysMessage(LANG_SELECT_CREATURE
);
5504 SetSentErrorMessage(true);
5507 Creature
* creature
= (Creature
*)unit
;
5508 if(creature
->UpdateEntry(newEntryNum
))
5509 SendSysMessage(LANG_DONE
);
5511 SendSysMessage(LANG_ERROR
);
5515 bool ChatHandler::HandleWritePDumpCommand(const char *args
)
5520 char* file
= strtok((char*)args
, " ");
5521 char* p2
= strtok(NULL
, " ");
5526 uint32 guid
= objmgr
.GetPlayerGUIDByName(p2
);
5530 if(!objmgr
.GetPlayerAccountIdByGUID(guid
))
5532 PSendSysMessage(LANG_PLAYER_NOT_FOUND
);
5533 SetSentErrorMessage(true);
5537 switch(PlayerDumpWriter().WriteDump(file
, guid
))
5540 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS
);
5542 case DUMP_FILE_OPEN_ERROR
:
5543 PSendSysMessage(LANG_FILE_OPEN_FAIL
,file
);
5544 SetSentErrorMessage(true);
5547 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED
);
5548 SetSentErrorMessage(true);
5555 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5557 Unit
* unit
= getSelectedUnit();
5560 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5561 SetSentErrorMessage(true);
5565 PSendSysMessage(LANG_MOVEGENS_LIST
,(unit
->GetTypeId()==TYPEID_PLAYER
? "Player" : "Creature" ),unit
->GetGUIDLow());
5567 MotionMaster
* mm
= unit
->GetMotionMaster();
5568 for(MotionMaster::const_iterator itr
= mm
->begin(); itr
!= mm
->end(); ++itr
)
5570 switch((*itr
)->GetMovementGeneratorType())
5572 case IDLE_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_IDLE
); break;
5573 case RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_RANDOM
); break;
5574 case WAYPOINT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_WAYPOINT
); break;
5575 case ANIMAL_RANDOM_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM
); break;
5576 case CONFUSED_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_CONFUSED
); break;
5577 case TARGETED_MOTION_TYPE
:
5579 if(unit
->GetTypeId()==TYPEID_PLAYER
)
5581 TargetedMovementGenerator
<Player
> const* mgen
= static_cast<TargetedMovementGenerator
<Player
> const*>(*itr
);
5582 Unit
* target
= mgen
->GetTarget();
5584 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER
,target
->GetName(),target
->GetGUIDLow());
5586 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5590 TargetedMovementGenerator
<Creature
> const* mgen
= static_cast<TargetedMovementGenerator
<Creature
> const*>(*itr
);
5591 Unit
* target
= mgen
->GetTarget();
5593 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE
,target
->GetName(),target
->GetGUIDLow());
5595 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL
);
5599 case HOME_MOTION_TYPE
:
5600 if(unit
->GetTypeId()==TYPEID_UNIT
)
5603 (*itr
)->GetDestination(x
,y
,z
);
5604 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE
,x
,y
,z
);
5607 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER
);
5609 case FLIGHT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FLIGHT
); break;
5610 case POINT_MOTION_TYPE
:
5613 (*itr
)->GetDestination(x
,y
,z
);
5614 PSendSysMessage(LANG_MOVEGENS_POINT
,x
,y
,z
);
5617 case FLEEING_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_FEAR
); break;
5618 case DISTRACT_MOTION_TYPE
: SendSysMessage(LANG_MOVEGENS_DISTRACT
); break;
5620 PSendSysMessage(LANG_MOVEGENS_UNKNOWN
,(*itr
)->GetMovementGeneratorType());
5627 bool ChatHandler::HandlePLimitCommand(const char *args
)
5631 char* param
= strtok((char*)args
, " ");
5635 int l
= strlen(param
);
5637 if( strncmp(param
,"player",l
) == 0 )
5638 sWorld
.SetPlayerLimit(-SEC_PLAYER
);
5639 else if(strncmp(param
,"moderator",l
) == 0 )
5640 sWorld
.SetPlayerLimit(-SEC_MODERATOR
);
5641 else if(strncmp(param
,"gamemaster",l
) == 0 )
5642 sWorld
.SetPlayerLimit(-SEC_GAMEMASTER
);
5643 else if(strncmp(param
,"administrator",l
) == 0 )
5644 sWorld
.SetPlayerLimit(-SEC_ADMINISTRATOR
);
5645 else if(strncmp(param
,"reset",l
) == 0 )
5646 sWorld
.SetPlayerLimit( sConfig
.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT
) );
5649 int val
= atoi(param
);
5650 if(val
< -SEC_ADMINISTRATOR
) val
= -SEC_ADMINISTRATOR
;
5652 sWorld
.SetPlayerLimit(val
);
5655 // kick all low security level players
5656 if(sWorld
.GetPlayerAmountLimit() > SEC_PLAYER
)
5657 sWorld
.KickAllLess(sWorld
.GetPlayerSecurityLimit());
5660 uint32 pLimit
= sWorld
.GetPlayerAmountLimit();
5661 AccountTypes allowedAccountType
= sWorld
.GetPlayerSecurityLimit();
5662 char const* secName
= "";
5663 switch(allowedAccountType
)
5665 case SEC_PLAYER
: secName
= "Player"; break;
5666 case SEC_MODERATOR
: secName
= "Moderator"; break;
5667 case SEC_GAMEMASTER
: secName
= "Gamemaster"; break;
5668 case SEC_ADMINISTRATOR
: secName
= "Administrator"; break;
5669 default: secName
= "<unknown>"; break;
5672 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit
,secName
);
5677 bool ChatHandler::HandleCastCommand(const char* args
)
5682 Unit
* target
= getSelectedUnit();
5686 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5687 SetSentErrorMessage(true);
5691 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5692 uint32 spell
= extractSpellIdFromLink((char*)args
);
5696 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5700 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5702 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5703 SetSentErrorMessage(true);
5707 char* trig_str
= strtok(NULL
, " ");
5710 int l
= strlen(trig_str
);
5711 if(strncmp(trig_str
,"triggered",l
) != 0 )
5715 bool triggered
= (trig_str
!= NULL
);
5717 m_session
->GetPlayer()->CastSpell(target
,spell
,triggered
);
5722 bool ChatHandler::HandleCastBackCommand(const char* args
)
5724 Creature
* caster
= getSelectedCreature();
5728 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5729 SetSentErrorMessage(true);
5733 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5734 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5735 uint32 spell
= extractSpellIdFromLink((char*)args
);
5736 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5739 char* trig_str
= strtok(NULL
, " ");
5742 int l
= strlen(trig_str
);
5743 if(strncmp(trig_str
,"triggered",l
) != 0 )
5747 bool triggered
= (trig_str
!= NULL
);
5749 // update orientation at server
5750 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5754 caster
->BuildHeartBeatMsg(&data
);
5755 caster
->SendMessageToSet(&data
,true);
5757 caster
->CastSpell(m_session
->GetPlayer(),spell
,triggered
);
5762 bool ChatHandler::HandleCastDistCommand(const char* args
)
5767 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5768 uint32 spell
= extractSpellIdFromLink((char*)args
);
5772 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5776 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5778 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5779 SetSentErrorMessage(true);
5783 char *distStr
= strtok(NULL
, " ");
5788 sscanf(distStr
, "%f", &dist
);
5790 char* trig_str
= strtok(NULL
, " ");
5793 int l
= strlen(trig_str
);
5794 if(strncmp(trig_str
,"triggered",l
) != 0 )
5798 bool triggered
= (trig_str
!= NULL
);
5801 m_session
->GetPlayer()->GetClosePoint(x
,y
,z
,dist
);
5803 m_session
->GetPlayer()->CastSpell(x
,y
,z
,spell
,triggered
);
5807 bool ChatHandler::HandleCastTargetCommand(const char* args
)
5809 Creature
* caster
= getSelectedCreature();
5813 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5814 SetSentErrorMessage(true);
5818 if(!caster
->getVictim())
5820 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM
);
5821 SetSentErrorMessage(true);
5825 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5826 uint32 spell
= extractSpellIdFromLink((char*)args
);
5827 if(!spell
|| !sSpellStore
.LookupEntry(spell
))
5830 char* trig_str
= strtok(NULL
, " ");
5833 int l
= strlen(trig_str
);
5834 if(strncmp(trig_str
,"triggered",l
) != 0 )
5838 bool triggered
= (trig_str
!= NULL
);
5840 // update orientation at server
5841 caster
->SetOrientation(caster
->GetAngle(m_session
->GetPlayer()));
5845 caster
->BuildHeartBeatMsg(&data
);
5846 caster
->SendMessageToSet(&data
,true);
5848 caster
->CastSpell(caster
->getVictim(),spell
,triggered
);
5854 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5855 Without this function 3rd party scripting library will get linking errors (unresolved external)
5856 when attempting to use the PointMovementGenerator
5858 bool ChatHandler::HandleComeToMeCommand(const char *args
)
5860 Creature
* caster
= getSelectedCreature();
5864 SendSysMessage(LANG_SELECT_CREATURE
);
5865 SetSentErrorMessage(true);
5869 char* newFlagStr
= strtok((char*)args
, " ");
5874 uint32 newFlags
= atoi(newFlagStr
);
5876 caster
->SetUnitMovementFlags(newFlags
);
5878 Player
* pl
= m_session
->GetPlayer();
5880 caster
->GetMotionMaster()->MovePoint(0, pl
->GetPositionX(), pl
->GetPositionY(), pl
->GetPositionZ());
5884 bool ChatHandler::HandleCastSelfCommand(const char* args
)
5889 Unit
* target
= getSelectedUnit();
5893 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
5894 SetSentErrorMessage(true);
5898 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5899 uint32 spell
= extractSpellIdFromLink((char*)args
);
5903 SpellEntry
const* spellInfo
= sSpellStore
.LookupEntry(spell
);
5907 if(!SpellMgr::IsSpellValid(spellInfo
,m_session
->GetPlayer()))
5909 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN
,spell
);
5910 SetSentErrorMessage(true);
5914 target
->CastSpell(target
,spell
,false);
5919 std::string
GetTimeString(uint32 time
)
5921 uint16 days
= time
/ DAY
, hours
= (time
% DAY
) / HOUR
, minute
= (time
% HOUR
) / MINUTE
;
5922 std::ostringstream ss
;
5923 if(days
) ss
<< days
<< "d ";
5924 if(hours
) ss
<< hours
<< "h ";
5925 ss
<< minute
<< "m";
5929 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5931 Player
* player
= getSelectedPlayer();
5932 if (!player
) player
= m_session
->GetPlayer();
5934 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5936 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5937 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5939 InstanceSave
*save
= itr
->second
.save
;
5940 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5941 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());
5945 PSendSysMessage("player binds: %d", counter
);
5947 Group
*group
= player
->GetGroup();
5950 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5952 Group::BoundInstancesMap
&binds
= group
->GetBoundInstances(i
);
5953 for(Group::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end(); ++itr
)
5955 InstanceSave
*save
= itr
->second
.save
;
5956 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5957 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());
5962 PSendSysMessage("group binds: %d", counter
);
5967 bool ChatHandler::HandleInstanceUnbindCommand(const char* args
)
5972 std::string cmd
= args
;
5975 Player
* player
= getSelectedPlayer();
5976 if (!player
) player
= m_session
->GetPlayer();
5978 for(uint8 i
= 0; i
< TOTAL_DIFFICULTIES
; i
++)
5980 Player::BoundInstancesMap
&binds
= player
->GetBoundInstances(i
);
5981 for(Player::BoundInstancesMap::iterator itr
= binds
.begin(); itr
!= binds
.end();)
5983 if(itr
->first
!= player
->GetMapId())
5985 InstanceSave
*save
= itr
->second
.save
;
5986 std::string timeleft
= GetTimeString(save
->GetResetTime() - time(NULL
));
5987 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());
5988 player
->UnbindInstance(itr
, i
);
5995 PSendSysMessage("instances unbound: %d", counter
);
6000 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6002 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6003 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6004 PSendSysMessage("instance saves: %d", sInstanceSaveManager
.GetNumInstanceSaves());
6005 PSendSysMessage("players bound: %d", sInstanceSaveManager
.GetNumBoundPlayersTotal());
6006 PSendSysMessage("groups bound: %d", sInstanceSaveManager
.GetNumBoundGroupsTotal());
6010 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6012 Player
* pl
= m_session
->GetPlayer();
6014 Map
* map
= pl
->GetMap();
6015 if (!map
->IsDungeon())
6017 PSendSysMessage("Map is not a dungeon.");
6018 SetSentErrorMessage(true);
6022 if (!((InstanceMap
*)map
)->GetInstanceData())
6024 PSendSysMessage("Map has no instance data.");
6025 SetSentErrorMessage(true);
6029 ((InstanceMap
*)map
)->GetInstanceData()->SaveToDB();
6033 /// Display the list of GMs
6034 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6036 ///- Get the accounts with GM Level >0
6037 QueryResult
*result
= loginDatabase
.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6040 SendSysMessage(LANG_GMLIST
);
6041 SendSysMessage("========================");
6042 SendSysMessage(LANG_GMLIST_HEADER
);
6043 SendSysMessage("========================");
6045 ///- Circle through them. Display username and GM level
6048 Field
*fields
= result
->Fetch();
6049 PSendSysMessage("|%15s|%6s|", fields
[0].GetString(),fields
[1].GetString());
6050 }while( result
->NextRow() );
6052 PSendSysMessage("========================");
6056 PSendSysMessage(LANG_GMLIST_EMPTY
);
6060 /// Define the 'Message of the day' for the realm
6061 bool ChatHandler::HandleServerSetMotdCommand(const char* args
)
6063 sWorld
.SetMotd(args
);
6064 PSendSysMessage(LANG_MOTD_NEW
, args
);
6068 /// Set/Unset the expansion level for an account
6069 bool ChatHandler::HandleAccountSetAddonCommand(const char* args
)
6071 ///- Get the command line arguments
6072 char *szAcc
= strtok((char*)args
," ");
6073 char *szExp
= strtok(NULL
," ");
6078 std::string account_name
;
6083 Player
* player
= getSelectedPlayer();
6087 account_id
= player
->GetSession()->GetAccountId();
6088 accmgr
.GetName(account_id
,account_name
);
6093 ///- Convert Account name to Upper Format
6094 account_name
= szAcc
;
6095 if(!AccountMgr::normilizeString(account_name
))
6097 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6098 SetSentErrorMessage(true);
6102 account_id
= accmgr
.GetId(account_name
);
6105 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST
,account_name
.c_str());
6106 SetSentErrorMessage(true);
6111 int lev
=atoi(szExp
); //get int anyway (0 if error)
6116 loginDatabase
.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev
,account_id
);
6117 PSendSysMessage(LANG_ACCOUNT_SETADDON
,account_name
.c_str(),account_id
,lev
);
6121 //Send items by mail
6122 bool ChatHandler::HandleSendItemsCommand(const char* args
)
6127 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6129 char* pName
= strtok((char*)args
, " ");
6133 char* tail1
= strtok(NULL
, "");
6139 msgSubject
= strtok(tail1
+1, "\"");
6142 char* space
= strtok(tail1
, "\"");
6145 msgSubject
= strtok(NULL
, "\"");
6151 char* tail2
= strtok(NULL
, "");
6157 msgText
= strtok(tail2
+1, "\"");
6160 char* space
= strtok(tail2
, "\"");
6163 msgText
= strtok(NULL
, "\"");
6169 // pName, msgSubject, msgText isn't NUL after prev. check
6170 std::string name
= pName
;
6171 std::string subject
= msgSubject
;
6172 std::string text
= msgText
;
6175 typedef std::pair
<uint32
,uint32
> ItemPair
;
6176 typedef std::list
< ItemPair
> ItemPairs
;
6179 // get all tail string
6180 char* tail
= strtok(NULL
, "");
6182 // get from tail next item str
6183 while(char* itemStr
= strtok(tail
, " "))
6186 tail
= strtok(NULL
, "");
6189 char* itemIdStr
= strtok(itemStr
, ":");
6190 char* itemCountStr
= strtok(NULL
, " ");
6192 uint32 item_id
= atoi(itemIdStr
);
6196 ItemPrototype
const* item_proto
= objmgr
.GetItemPrototype(item_id
);
6199 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID
, item_id
);
6200 SetSentErrorMessage(true);
6204 uint32 item_count
= itemCountStr
? atoi(itemCountStr
) : 1;
6205 if(item_count
< 1 || item_proto
->MaxCount
&& item_count
> item_proto
->MaxCount
)
6207 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT
, item_count
,item_id
);
6208 SetSentErrorMessage(true);
6212 while(item_count
> item_proto
->Stackable
)
6214 items
.push_back(ItemPair(item_id
,item_proto
->Stackable
));
6215 item_count
-= item_proto
->Stackable
;
6218 items
.push_back(ItemPair(item_id
,item_count
));
6220 if(items
.size() > MAX_MAIL_ITEMS
)
6222 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT
, MAX_MAIL_ITEMS
);
6223 SetSentErrorMessage(true);
6228 if(!normalizePlayerName(name
))
6230 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6231 SetSentErrorMessage(true);
6235 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6238 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6239 SetSentErrorMessage(true);
6243 // from console show not existed sender
6244 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6246 uint32 messagetype
= MAIL_NORMAL
;
6247 uint32 stationery
= MAIL_STATIONERY_GM
;
6248 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6250 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6253 MailItemsInfo mi
; // item list preparing
6255 for(ItemPairs::const_iterator itr
= items
.begin(); itr
!= items
.end(); ++itr
)
6257 if(Item
* item
= Item::CreateItem(itr
->first
,itr
->second
,m_session
? m_session
->GetPlayer() : 0))
6259 item
->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6260 mi
.AddItem(item
->GetGUIDLow(), item
->GetEntry(), item
);
6264 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, &mi
, 0, 0, MAIL_CHECK_MASK_NONE
);
6266 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6270 ///Send money by mail
6271 bool ChatHandler::HandleSendMoneyCommand(const char* args
)
6276 /// format: name "subject text" "mail text" money
6278 char* pName
= strtok((char*)args
, " ");
6282 char* tail1
= strtok(NULL
, "");
6288 msgSubject
= strtok(tail1
+1, "\"");
6291 char* space
= strtok(tail1
, "\"");
6294 msgSubject
= strtok(NULL
, "\"");
6300 char* tail2
= strtok(NULL
, "");
6306 msgText
= strtok(tail2
+1, "\"");
6309 char* space
= strtok(tail2
, "\"");
6312 msgText
= strtok(NULL
, "\"");
6318 int32 money
= atoi(strtok(NULL
, ""));
6322 // pName, msgSubject, msgText isn't NUL after prev. check
6323 std::string name
= pName
;
6324 std::string subject
= msgSubject
;
6325 std::string text
= msgText
;
6327 if (!normalizePlayerName(name
))
6329 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6330 SetSentErrorMessage(true);
6334 uint64 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
6337 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6338 SetSentErrorMessage(true);
6342 uint32 mailId
= objmgr
.GenerateMailID();
6344 // from console show not existed sender
6345 uint32 sender_guidlo
= m_session
? m_session
->GetPlayer()->GetGUIDLow() : 0;
6347 uint32 messagetype
= MAIL_NORMAL
;
6348 uint32 stationery
= MAIL_STATIONERY_GM
;
6349 uint32 itemTextId
= !text
.empty() ? objmgr
.CreateItemText( text
) : 0;
6351 Player
*receiver
= objmgr
.GetPlayer(receiver_guid
);
6353 WorldSession::SendMailTo(receiver
,messagetype
, stationery
, sender_guidlo
, GUID_LOPART(receiver_guid
), subject
, itemTextId
, NULL
, money
, 0, MAIL_CHECK_MASK_NONE
);
6355 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
6359 /// Send a message to a player in game
6360 bool ChatHandler::HandleSendMessageCommand(const char* args
)
6362 ///- Get the command line arguments
6363 char* name_str
= strtok((char*)args
, " ");
6364 char* msg_str
= strtok(NULL
, "");
6366 if(!name_str
|| !msg_str
)
6369 std::string name
= name_str
;
6371 if(!normalizePlayerName(name
))
6374 ///- Find the player and check that he is not logging out.
6375 Player
*rPlayer
= objmgr
.GetPlayer(name
.c_str());
6378 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6379 SetSentErrorMessage(true);
6383 if(rPlayer
->GetSession()->isLogingOut())
6385 SendSysMessage(LANG_PLAYER_NOT_FOUND
);
6386 SetSentErrorMessage(true);
6390 ///- Send the message
6391 //Use SendAreaTriggerMessage for fastest delivery.
6392 rPlayer
->GetSession()->SendAreaTriggerMessage("%s", msg_str
);
6393 rPlayer
->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6395 //Confirmation message
6396 PSendSysMessage(LANG_SENDMESSAGE
,name
.c_str(),msg_str
);
6400 bool ChatHandler::HandleModifyGenderCommand(const char *args
)
6405 Player
*player
= getSelectedPlayer();
6409 PSendSysMessage(LANG_NO_PLAYER
);
6410 SetSentErrorMessage(true);
6414 char const* gender_str
= (char*)args
;
6415 int gender_len
= strlen(gender_str
);
6417 uint32 displayId
= player
->GetNativeDisplayId();
6418 char const* gender_full
= NULL
;
6419 uint32 new_displayId
= displayId
;
6422 if(!strncmp(gender_str
,"male",gender_len
)) // MALE
6424 if(player
->getGender() == GENDER_MALE
)
6427 gender_full
= "male";
6428 new_displayId
= player
->getRace() == RACE_BLOODELF
? displayId
+1 : displayId
-1;
6429 gender
= GENDER_MALE
;
6431 else if (!strncmp(gender_str
,"female",gender_len
)) // FEMALE
6433 if(player
->getGender() == GENDER_FEMALE
)
6436 gender_full
= "female";
6437 new_displayId
= player
->getRace() == RACE_BLOODELF
? displayId
-1 : displayId
+1;
6438 gender
= GENDER_FEMALE
;
6442 SendSysMessage(LANG_MUST_MALE_OR_FEMALE
);
6443 SetSentErrorMessage(true);
6448 player
->SetByteValue(UNIT_FIELD_BYTES_0
, 2, gender
);
6450 // Change display ID
6451 player
->SetDisplayId(new_displayId
);
6452 player
->SetNativeDisplayId(new_displayId
);
6454 PSendSysMessage(LANG_YOU_CHANGE_GENDER
, player
->GetName(),gender_full
);
6455 if (needReportToTarget(player
))
6456 ChatHandler(player
).PSendSysMessage(LANG_YOUR_GENDER_CHANGED
, gender_full
,GetName());