Merge branch 'master' into 303
[getmangos.git] / src / game / Level3.cpp
blob8732eaf4b15b03215a267e9fd1866faeb9a27d8c
1 /*
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
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
38 #include "Language.h"
39 #include "GridNotifiersImpl.h"
40 #include "CellImpl.h"
41 #include "Weather.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"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
53 //reload commands
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);
59 return false;
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("");
79 return true;
82 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
84 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
85 HandleReloadAreaTriggerTeleportCommand("");
86 HandleReloadAreaTriggerTavernCommand("");
87 HandleReloadGameGraveyardZoneCommand("");
88 return true;
91 bool ChatHandler::HandleReloadAllLootCommand(const char*)
93 sLog.outString( "Re-Loading Loot Tables..." );
94 LoadLootTables();
95 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
96 return true;
99 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
101 HandleReloadNpcGossipCommand("a");
102 HandleReloadNpcOptionCommand("a");
103 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
105 return true;
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.");
116 return true;
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
125 return false;
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.");
135 return true;
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");
151 return true;
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
158 return true;
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");
169 return true;
172 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
174 sLog.outString( "Re-Loading config settings..." );
175 sWorld.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
177 return true;
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
185 return true;
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
193 return true;
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table = true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
200 return true;
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.");
208 return true;
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.");
216 return true;
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.");
224 return true;
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.");
232 return true;
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.");
240 return true;
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog.outString( "Re-Loading Quest Templates..." );
246 objmgr.LoadQuests();
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
248 return true;
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.");
257 return true;
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.");
266 return true;
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.");
275 return true;
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.");
284 return true;
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.");
293 return true;
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.");
302 return true;
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.");
311 return true;
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.");
320 return true;
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.");
328 return true;
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.");
337 return true;
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog.outString( "Re-Loading mangos_string Table!" );
343 objmgr.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
345 return true;
348 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
350 sLog.outString( "Re-Loading `npc_option` Table!" );
351 objmgr.LoadNpcOptions();
352 SendGlobalSysMessage("DB table `npc_option` reloaded.");
353 return true;
356 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
358 sLog.outString( "Re-Loading `npc_gossip` Table!" );
359 objmgr.LoadNpcTextId();
360 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
361 return true;
364 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
366 sLog.outString( "Re-Loading `npc_trainer` Table!" );
367 objmgr.LoadTrainerSpell();
368 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
369 return true;
372 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
374 sLog.outString( "Re-Loading `npc_vendor` Table!" );
375 objmgr.LoadVendors();
376 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
377 return true;
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.");
385 return true;
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.");
393 return true;
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.");
401 return true;
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.");
409 return true;
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.");
417 return true;
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.");
425 return true;
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.");
433 return true;
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.");
441 return true;
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.");
449 return true;
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.");
457 return true;
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.");
465 return true;
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.");
473 return true;
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.");
481 return true;
484 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
486 sLog.outString( "Re-Loading Page Texts..." );
487 objmgr.LoadPageTexts();
488 SendGlobalSysMessage("DB table `page_texts` reloaded.");
489 return true;
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.");
497 return true;
500 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
502 if(sWorld.IsScriptScheduled())
504 SendSysMessage("DB scripts used currently, please attempt reload later.");
505 SetSentErrorMessage(true);
506 return false;
509 if(*arg!='a')
510 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
512 objmgr.LoadGameObjectScripts();
514 if(*arg!='a')
515 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
517 return true;
520 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
522 if(sWorld.IsScriptScheduled())
524 SendSysMessage("DB scripts used currently, please attempt reload later.");
525 SetSentErrorMessage(true);
526 return false;
529 if(*arg!='a')
530 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
532 objmgr.LoadEventScripts();
534 if(*arg!='a')
535 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
537 return true;
540 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
542 if(sWorld.IsScriptScheduled())
544 SendSysMessage("DB scripts used currently, please attempt reload later.");
545 SetSentErrorMessage(true);
546 return false;
549 if(*arg!='a')
550 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
552 objmgr.LoadQuestEndScripts();
554 if(*arg!='a')
555 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
557 return true;
560 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
562 if(sWorld.IsScriptScheduled())
564 SendSysMessage("DB scripts used currently, please attempt reload later.");
565 SetSentErrorMessage(true);
566 return false;
569 if(*arg!='a')
570 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
572 objmgr.LoadQuestStartScripts();
574 if(*arg!='a')
575 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
577 return true;
580 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
582 if(sWorld.IsScriptScheduled())
584 SendSysMessage("DB scripts used currently, please attempt reload later.");
585 SetSentErrorMessage(true);
586 return false;
589 if(*arg!='a')
590 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
592 objmgr.LoadSpellScripts();
594 if(*arg!='a')
595 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
597 return true;
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.");
608 return true;
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.");
619 return true;
622 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
624 sLog.outString( "Re-Loading Locales Creature ...");
625 objmgr.LoadCreatureLocales();
626 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
627 return true;
630 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
632 sLog.outString( "Re-Loading Locales Gameobject ... ");
633 objmgr.LoadGameObjectLocales();
634 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
635 return true;
638 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
640 sLog.outString( "Re-Loading Locales Item ... ");
641 objmgr.LoadItemLocales();
642 SendGlobalSysMessage("DB table `locales_item` reloaded.");
643 return true;
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.");
651 return true;
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.");
659 return true;
662 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
664 sLog.outString( "Re-Loading Locales Quest ... ");
665 objmgr.LoadQuestLocales();
666 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
667 return true;
670 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
672 if(!LoadScriptingModule(args)) return true;
674 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
675 return true;
678 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
680 char* arg1 = strtok((char*)args, " ");
681 if( !arg1 )
682 return false;
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
696 if(arg2)
697 return false;
699 /// security level expected in arg2 after this if.
700 arg2 = arg1;
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);
708 return false;
711 else
713 /// wrong command syntax (second arg expected)
714 if(!arg2)
715 return false;
717 targetAccountName = arg1;
718 if(!AccountMgr::normilizeString(targetAccountName))
720 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
721 SetSentErrorMessage(true);
722 return false;
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);
734 return false;
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);
746 return false;
749 if(targetPlayer)
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);
758 return true;
761 /// Set password for account
762 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
764 if(!*args)
765 return false;
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)
773 return false;
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);
780 return false;
783 uint32 targetAccountId = accmgr.GetId(account_name);
784 if (!targetAccountId)
786 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
787 SetSentErrorMessage(true);
788 return false;
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);
802 return false;
805 if (strcmp(szPassword1,szPassword2))
807 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
808 SetSentErrorMessage (true);
809 return false;
812 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
814 switch(result)
816 case AOR_OK:
817 SendSysMessage(LANG_COMMAND_PASSWORD);
818 break;
819 case AOR_NAME_NOT_EXIST:
820 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
821 SetSentErrorMessage(true);
822 return false;
823 case AOR_PASS_TOO_LONG:
824 SendSysMessage(LANG_PASSWORD_TOO_LONG);
825 SetSentErrorMessage(true);
826 return false;
827 default:
828 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
829 SetSentErrorMessage(true);
830 return false;
833 return true;
836 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
838 if(sWorld.getAllowMovement())
840 sWorld.SetAllowMovement(false);
841 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
843 else
845 sWorld.SetAllowMovement(true);
846 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
848 return true;
851 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
853 Player* SelectedPlayer = getSelectedPlayer();
854 if(!SelectedPlayer)
856 SendSysMessage(LANG_NO_CHAR_SELECTED);
857 SetSentErrorMessage(true);
858 return false;
861 // each skills that have max skill value dependent from level seted to current level max skill value
862 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
863 return true;
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");
870 if(!skill_p)
871 return false;
873 char *level_p = strtok (NULL, " ");
875 if( !level_p)
876 return false;
878 char *max_p = strtok (NULL, " ");
880 int32 skill = atoi(skill_p);
882 if (skill <= 0)
884 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
885 SetSentErrorMessage(true);
886 return false;
889 int32 level = atol (level_p);
891 Player * target = getSelectedPlayer();
892 if(!target)
894 SendSysMessage(LANG_NO_CHAR_SELECTED);
895 SetSentErrorMessage(true);
896 return false;
899 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
900 if(!sl)
902 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
903 SetSentErrorMessage(true);
904 return false;
907 if(!target->GetSkillValue(skill))
909 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
910 SetSentErrorMessage(true);
911 return false;
914 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
916 if( level <= 0 || level > max || max <= 0 )
917 return false;
919 target->SetSkill(skill, level, max);
920 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
922 return true;
925 bool ChatHandler::HandleUnLearnCommand(const char* args)
927 if (!*args)
928 return false;
930 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
931 uint32 min_id = extractSpellIdFromLink((char*)args);
932 if(!min_id)
933 return false;
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);
940 if (!max_id)
942 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
943 max_id = min_id+1;
945 else
947 if (max_id < min_id)
948 std::swap(min_id,max_id);
950 max_id=max_id+1;
953 Player* target = getSelectedPlayer();
954 if(!target)
956 SendSysMessage(LANG_NO_CHAR_SELECTED);
957 SetSentErrorMessage(true);
958 return false;
961 for(uint32 spell=min_id;spell<max_id;spell++)
963 if (target->HasSpell(spell))
964 target->removeSpell(spell);
965 else
966 SendSysMessage(LANG_FORGET_SPELL);
969 return true;
972 bool ChatHandler::HandleCooldownCommand(const char* args)
974 Player* target = getSelectedPlayer();
975 if(!target)
977 SendSysMessage(LANG_PLAYER_NOT_FOUND);
978 SetSentErrorMessage(true);
979 return false;
982 if (!*args)
984 target->RemoveAllSpellCooldown();
985 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
987 else
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);
991 if(!spell_id)
992 return false;
994 if(!sSpellStore.LookupEntry(spell_id))
996 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
997 SetSentErrorMessage(true);
998 return false;
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());
1008 return true;
1011 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1013 static const char *allSpellList[] =
1015 "3365",
1016 "6233",
1017 "6247",
1018 "6246",
1019 "6477",
1020 "6478",
1021 "22810",
1022 "8386",
1023 "21651",
1024 "21652",
1025 "522",
1026 "7266",
1027 "8597",
1028 "2479",
1029 "22027",
1030 "6603",
1031 "5019",
1032 "133",
1033 "168",
1034 "227",
1035 "5009",
1036 "9078",
1037 "668",
1038 "203",
1039 "20599",
1040 "20600",
1041 "81",
1042 "20597",
1043 "20598",
1044 "20864",
1045 "1459",
1046 "5504",
1047 "587",
1048 "5143",
1049 "118",
1050 "5505",
1051 "597",
1052 "604",
1053 "1449",
1054 "1460",
1055 "2855",
1056 "1008",
1057 "475",
1058 "5506",
1059 "1463",
1060 "12824",
1061 "8437",
1062 "990",
1063 "5145",
1064 "8450",
1065 "1461",
1066 "759",
1067 "8494",
1068 "8455",
1069 "8438",
1070 "6127",
1071 "8416",
1072 "6129",
1073 "8451",
1074 "8495",
1075 "8439",
1076 "3552",
1077 "8417",
1078 "10138",
1079 "12825",
1080 "10169",
1081 "10156",
1082 "10144",
1083 "10191",
1084 "10201",
1085 "10211",
1086 "10053",
1087 "10173",
1088 "10139",
1089 "10145",
1090 "10192",
1091 "10170",
1092 "10202",
1093 "10054",
1094 "10174",
1095 "10193",
1096 "12826",
1097 "2136",
1098 "143",
1099 "145",
1100 "2137",
1101 "2120",
1102 "3140",
1103 "543",
1104 "2138",
1105 "2948",
1106 "8400",
1107 "2121",
1108 "8444",
1109 "8412",
1110 "8457",
1111 "8401",
1112 "8422",
1113 "8445",
1114 "8402",
1115 "8413",
1116 "8458",
1117 "8423",
1118 "8446",
1119 "10148",
1120 "10197",
1121 "10205",
1122 "10149",
1123 "10215",
1124 "10223",
1125 "10206",
1126 "10199",
1127 "10150",
1128 "10216",
1129 "10207",
1130 "10225",
1131 "10151",
1132 "116",
1133 "205",
1134 "7300",
1135 "122",
1136 "837",
1137 "10",
1138 "7301",
1139 "7322",
1140 "6143",
1141 "120",
1142 "865",
1143 "8406",
1144 "6141",
1145 "7302",
1146 "8461",
1147 "8407",
1148 "8492",
1149 "8427",
1150 "8408",
1151 "6131",
1152 "7320",
1153 "10159",
1154 "8462",
1155 "10185",
1156 "10179",
1157 "10160",
1158 "10180",
1159 "10219",
1160 "10186",
1161 "10177",
1162 "10230",
1163 "10181",
1164 "10161",
1165 "10187",
1166 "10220",
1167 "2018",
1168 "2663",
1169 "12260",
1170 "2660",
1171 "3115",
1172 "3326",
1173 "2665",
1174 "3116",
1175 "2738",
1176 "3293",
1177 "2661",
1178 "3319",
1179 "2662",
1180 "9983",
1181 "8880",
1182 "2737",
1183 "2739",
1184 "7408",
1185 "3320",
1186 "2666",
1187 "3323",
1188 "3324",
1189 "3294",
1190 "22723",
1191 "23219",
1192 "23220",
1193 "23221",
1194 "23228",
1195 "23338",
1196 "10788",
1197 "10790",
1198 "5611",
1199 "5016",
1200 "5609",
1201 "2060",
1202 "10963",
1203 "10964",
1204 "10965",
1205 "22593",
1206 "22594",
1207 "596",
1208 "996",
1209 "499",
1210 "768",
1211 "17002",
1212 "1448",
1213 "1082",
1214 "16979",
1215 "1079",
1216 "5215",
1217 "20484",
1218 "5221",
1219 "15590",
1220 "17007",
1221 "6795",
1222 "6807",
1223 "5487",
1224 "1446",
1225 "1066",
1226 "5421",
1227 "3139",
1228 "779",
1229 "6811",
1230 "6808",
1231 "1445",
1232 "5216",
1233 "1737",
1234 "5222",
1235 "5217",
1236 "1432",
1237 "6812",
1238 "9492",
1239 "5210",
1240 "3030",
1241 "1441",
1242 "783",
1243 "6801",
1244 "20739",
1245 "8944",
1246 "9491",
1247 "22569",
1248 "5226",
1249 "6786",
1250 "1433",
1251 "8973",
1252 "1828",
1253 "9495",
1254 "9006",
1255 "6794",
1256 "8993",
1257 "5203",
1258 "16914",
1259 "6784",
1260 "9635",
1261 "22830",
1262 "20722",
1263 "9748",
1264 "6790",
1265 "9753",
1266 "9493",
1267 "9752",
1268 "9831",
1269 "9825",
1270 "9822",
1271 "5204",
1272 "5401",
1273 "22831",
1274 "6793",
1275 "9845",
1276 "17401",
1277 "9882",
1278 "9868",
1279 "20749",
1280 "9893",
1281 "9899",
1282 "9895",
1283 "9832",
1284 "9902",
1285 "9909",
1286 "22832",
1287 "9828",
1288 "9851",
1289 "9883",
1290 "9869",
1291 "17406",
1292 "17402",
1293 "9914",
1294 "20750",
1295 "9897",
1296 "9848",
1297 "3127",
1298 "107",
1299 "204",
1300 "9116",
1301 "2457",
1302 "78",
1303 "18848",
1304 "331",
1305 "403",
1306 "2098",
1307 "1752",
1308 "11278",
1309 "11288",
1310 "11284",
1311 "6461",
1312 "2344",
1313 "2345",
1314 "6463",
1315 "2346",
1316 "2352",
1317 "775",
1318 "1434",
1319 "1612",
1320 "71",
1321 "2468",
1322 "2458",
1323 "2467",
1324 "7164",
1325 "7178",
1326 "7367",
1327 "7376",
1328 "7381",
1329 "21156",
1330 "5209",
1331 "3029",
1332 "5201",
1333 "9849",
1334 "9850",
1335 "20719",
1336 "22568",
1337 "22827",
1338 "22828",
1339 "22829",
1340 "6809",
1341 "8972",
1342 "9005",
1343 "9823",
1344 "9827",
1345 "6783",
1346 "9913",
1347 "6785",
1348 "6787",
1349 "9866",
1350 "9867",
1351 "9894",
1352 "9896",
1353 "6800",
1354 "8992",
1355 "9829",
1356 "9830",
1357 "780",
1358 "769",
1359 "6749",
1360 "6750",
1361 "9755",
1362 "9754",
1363 "9908",
1364 "20745",
1365 "20742",
1366 "20747",
1367 "20748",
1368 "9746",
1369 "9745",
1370 "9880",
1371 "9881",
1372 "5391",
1373 "842",
1374 "3025",
1375 "3031",
1376 "3287",
1377 "3329",
1378 "1945",
1379 "3559",
1380 "4933",
1381 "4934",
1382 "4935",
1383 "4936",
1384 "5142",
1385 "5390",
1386 "5392",
1387 "5404",
1388 "5420",
1389 "6405",
1390 "7293",
1391 "7965",
1392 "8041",
1393 "8153",
1394 "9033",
1395 "9034",
1396 //"9036", problems with ghost state
1397 "16421",
1398 "21653",
1399 "22660",
1400 "5225",
1401 "9846",
1402 "2426",
1403 "5916",
1404 "6634",
1405 //"6718", phasing stealth, annoying for learn all case.
1406 "6719",
1407 "8822",
1408 "9591",
1409 "9590",
1410 "10032",
1411 "17746",
1412 "17747",
1413 "8203",
1414 "11392",
1415 "12495",
1416 "16380",
1417 "23452",
1418 "4079",
1419 "4996",
1420 "4997",
1421 "4998",
1422 "4999",
1423 "5000",
1424 "6348",
1425 "6349",
1426 "6481",
1427 "6482",
1428 "6483",
1429 "6484",
1430 "11362",
1431 "11410",
1432 "11409",
1433 "12510",
1434 "12509",
1435 "12885",
1436 "13142",
1437 "21463",
1438 "23460",
1439 "11421",
1440 "11416",
1441 "11418",
1442 "1851",
1443 "10059",
1444 "11423",
1445 "11417",
1446 "11422",
1447 "11419",
1448 "11424",
1449 "11420",
1450 "27",
1451 "31",
1452 "33",
1453 "34",
1454 "35",
1455 "15125",
1456 "21127",
1457 "22950",
1458 "1180",
1459 "201",
1460 "12593",
1461 "12842",
1462 "16770",
1463 "6057",
1464 "12051",
1465 "18468",
1466 "12606",
1467 "12605",
1468 "18466",
1469 "12502",
1470 "12043",
1471 "15060",
1472 "12042",
1473 "12341",
1474 "12848",
1475 "12344",
1476 "12353",
1477 "18460",
1478 "11366",
1479 "12350",
1480 "12352",
1481 "13043",
1482 "11368",
1483 "11113",
1484 "12400",
1485 "11129",
1486 "16766",
1487 "12573",
1488 "15053",
1489 "12580",
1490 "12475",
1491 "12472",
1492 "12953",
1493 "12488",
1494 "11189",
1495 "12985",
1496 "12519",
1497 "16758",
1498 "11958",
1499 "12490",
1500 "11426",
1501 "3565",
1502 "3562",
1503 "18960",
1504 "3567",
1505 "3561",
1506 "3566",
1507 "3563",
1508 "1953",
1509 "2139",
1510 "12505",
1511 "13018",
1512 "12522",
1513 "12523",
1514 "5146",
1515 "5144",
1516 "5148",
1517 "8419",
1518 "8418",
1519 "10213",
1520 "10212",
1521 "10157",
1522 "12524",
1523 "13019",
1524 "12525",
1525 "13020",
1526 "12526",
1527 "13021",
1528 "18809",
1529 "13031",
1530 "13032",
1531 "13033",
1532 "4036",
1533 "3920",
1534 "3919",
1535 "3918",
1536 "7430",
1537 "3922",
1538 "3923",
1539 "7411",
1540 "7418",
1541 "7421",
1542 "13262",
1543 "7412",
1544 "7415",
1545 "7413",
1546 "7416",
1547 "13920",
1548 "13921",
1549 "7745",
1550 "7779",
1551 "7428",
1552 "7457",
1553 "7857",
1554 "7748",
1555 "7426",
1556 "13421",
1557 "7454",
1558 "13378",
1559 "7788",
1560 "14807",
1561 "14293",
1562 "7795",
1563 "6296",
1564 "20608",
1565 "755",
1566 "444",
1567 "427",
1568 "428",
1569 "442",
1570 "447",
1571 "3578",
1572 "3581",
1573 "19027",
1574 "3580",
1575 "665",
1576 "3579",
1577 "3577",
1578 "6755",
1579 "3576",
1580 "2575",
1581 "2577",
1582 "2578",
1583 "2579",
1584 "2580",
1585 "2656",
1586 "2657",
1587 "2576",
1588 "3564",
1589 "10248",
1590 "8388",
1591 "2659",
1592 "14891",
1593 "3308",
1594 "3307",
1595 "10097",
1596 "2658",
1597 "3569",
1598 "16153",
1599 "3304",
1600 "10098",
1601 "4037",
1602 "3929",
1603 "3931",
1604 "3926",
1605 "3924",
1606 "3930",
1607 "3977",
1608 "3925",
1609 "136",
1610 "228",
1611 "5487",
1612 "43",
1613 "202",
1617 int loop = 0;
1618 while(strcmp(allSpellList[loop], "0"))
1620 uint32 spell = atol((char*)allSpellList[loop++]);
1622 if (m_session->GetPlayer()->HasSpell(spell))
1623 continue;
1625 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1626 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1628 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1629 continue;
1632 m_session->GetPlayer()->learnSpell(spell);
1635 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1637 return true;
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
1650 "31899", // Kill
1651 "31924", // Kill
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);
1669 continue;
1672 m_session->GetPlayer()->learnSpell(spell);
1675 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1676 return true;
1679 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1681 HandleLearnAllMySpellsCommand("");
1682 HandleLearnAllMyTalentsCommand("");
1683 return true;
1686 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1688 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1689 if(!clsEntry)
1690 return true;
1691 uint32 family = clsEntry->spellfamily;
1693 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1695 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1696 if(!spellInfo)
1697 continue;
1699 // skip wrong class/race skills
1700 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1701 continue;
1703 // skip other spell families
1704 if( spellInfo->SpellFamilyName != family)
1705 continue;
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 )
1712 continue;
1714 // skip broken spells
1715 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1716 continue;
1718 m_session->GetPlayer()->learnSpell(i);
1721 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1722 return true;
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);
1743 if(!talentInfo)
1744 continue;
1746 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1747 if(!talentTabInfo)
1748 continue;
1750 if( (classMask & talentTabInfo->ClassMask) == 0 )
1751 continue;
1753 // search highest talent rank
1754 uint32 spellid = 0;
1755 int rank = 4;
1756 for(; rank >= 0; --rank)
1758 if(talentInfo->RankID[rank]!=0)
1760 spellid = talentInfo->RankID[rank];
1761 break;
1765 if(!spellid) // ??? none spells in talent
1766 continue;
1768 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1769 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1770 continue;
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);
1780 return true;
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);
1790 return true;
1793 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1795 char* pName = strtok((char*)args, "");
1796 Player *player = NULL;
1797 if (pName)
1799 std::string name = pName;
1801 if(!normalizePlayerName(name))
1803 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1804 SetSentErrorMessage(true);
1805 return false;
1808 player = objmgr.GetPlayer(name.c_str());
1810 else
1811 player = getSelectedPlayer();
1813 if(!player)
1815 SendSysMessage(LANG_NO_CHAR_SELECTED);
1816 SetSentErrorMessage(true);
1817 return false;
1820 player->learnDefaultSpells();
1821 player->learnQuestRewardedSpells();
1823 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1824 return true;
1827 bool ChatHandler::HandleLearnCommand(const char* args)
1829 Player* targetPlayer = getSelectedPlayer();
1831 if(!targetPlayer)
1833 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1834 SetSentErrorMessage(true);
1835 return false;
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))
1841 return false;
1843 if (targetPlayer->HasSpell(spell))
1845 if(targetPlayer == m_session->GetPlayer())
1846 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1847 else
1848 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1849 SetSentErrorMessage(true);
1850 return false;
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);
1858 return false;
1861 targetPlayer->learnSpell(spell);
1863 return true;
1866 bool ChatHandler::HandleAddItemCommand(const char* args)
1868 if (!*args)
1869 return false;
1871 uint32 itemId = 0;
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());
1882 if (!result)
1884 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1885 SetSentErrorMessage(true);
1886 return false;
1888 itemId = result->Fetch()->GetUInt16();
1889 delete result;
1891 else
1892 return false;
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");
1897 if(!cId)
1898 return false;
1899 itemId = atol(cId);
1902 char* ccount = strtok(NULL, " ");
1904 int32 count = 1;
1906 if (ccount)
1907 count = strtol(ccount, NULL, 10);
1909 if (count == 0)
1910 count = 1;
1912 Player* pl = m_session->GetPlayer();
1913 Player* plTarget = getSelectedPlayer();
1914 if(!plTarget)
1915 plTarget = pl;
1917 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1919 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1920 if(!pProto)
1922 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1923 SetSentErrorMessage(true);
1924 return false;
1927 //Subtract
1928 if (count < 0)
1930 plTarget->DestroyItemCount(itemId, -count, true, false);
1931 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1932 return true;
1935 //Adding items
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);
1948 return false;
1951 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1953 // remove binding (let GM give it to another player later)
1954 if(pl==plTarget)
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);
1962 if(pl!=plTarget)
1963 plTarget->SendNewItem(item,count,true,false);
1966 if(noSpaceForCount > 0)
1967 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1969 return true;
1972 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1974 if (!*args)
1975 return false;
1977 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1978 if (!cId)
1979 return false;
1981 uint32 itemsetId = atol(cId);
1983 // prevent generation all items with itemset field value '0'
1984 if (itemsetId == 0)
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1987 SetSentErrorMessage(true);
1988 return false;
1991 Player* pl = m_session->GetPlayer();
1992 Player* plTarget = getSelectedPlayer();
1993 if(!plTarget)
1994 plTarget = pl;
1996 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1998 bool found = false;
1999 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2001 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2002 if (!pProto)
2003 continue;
2005 if (pProto->ItemSet == itemsetId)
2007 found = true;
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)
2015 if (pl==plTarget)
2016 item->SetBinding( false );
2018 pl->SendNewItem(item,1,false,true);
2019 if (pl!=plTarget)
2020 plTarget->SendNewItem(item,1,true,false);
2022 else
2024 pl->SendEquipError( msg, NULL, NULL );
2025 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2030 if (!found)
2032 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2034 SetSentErrorMessage(true);
2035 return false;
2038 return true;
2041 bool ChatHandler::HandleListItemCommand(const char* args)
2043 if(!*args)
2044 return false;
2046 char* cId = extractKeyFromLink((char*)args,"Hitem");
2047 if(!cId)
2048 return false;
2050 uint32 item_id = atol(cId);
2051 if(!item_id)
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2054 SetSentErrorMessage(true);
2055 return false;
2058 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2059 if(!itemProto)
2061 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2062 SetSentErrorMessage(true);
2063 return false;
2066 char* c_count = strtok(NULL, " ");
2067 int count = c_count ? atol(c_count) : 10;
2069 if(count < 0)
2070 return false;
2072 QueryResult *result;
2074 // inventory case
2075 uint32 inv_count = 0;
2076 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2077 if(result)
2079 inv_count = (*result)[0].GetUInt32();
2080 delete result;
2083 result=CharacterDatabase.PQuery(
2084 // 0 1 2 3 4 5
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));
2090 if(result)
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]";
2109 else
2110 item_pos = "";
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();
2118 delete result;
2120 if(count > res_count)
2121 count-=res_count;
2122 else if(count)
2123 count = 0;
2126 // mail case
2127 uint32 mail_count = 0;
2128 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2129 if(result)
2131 mail_count = (*result)[0].GetUInt32();
2132 delete result;
2135 if(count > 0)
2137 result=CharacterDatabase.PQuery(
2138 // 0 1 2 3 4 5 6
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));
2144 else
2145 result = NULL;
2147 if(result)
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();
2168 delete result;
2170 if(count > res_count)
2171 count-=res_count;
2172 else if(count)
2173 count = 0;
2176 // auction case
2177 uint32 auc_count = 0;
2178 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2179 if(result)
2181 auc_count = (*result)[0].GetUInt32();
2182 delete result;
2185 if(count > 0)
2187 result=CharacterDatabase.PQuery(
2188 // 0 1 2 3
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));
2193 else
2194 result = NULL;
2196 if(result)
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());
2211 delete result;
2214 // guild bank case
2215 uint32 guild_count = 0;
2216 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2217 if(result)
2219 guild_count = (*result)[0].GetUInt32();
2220 delete result;
2223 result=CharacterDatabase.PQuery(
2224 // 0 1 2
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));
2229 if(result)
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();
2245 delete result;
2247 if(count > res_count)
2248 count-=res_count;
2249 else if(count)
2250 count = 0;
2253 if(inv_count+mail_count+auc_count+guild_count == 0)
2255 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2256 SetSentErrorMessage(true);
2257 return false;
2260 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2262 return true;
2265 bool ChatHandler::HandleListObjectCommand(const char* args)
2267 if(!*args)
2268 return false;
2270 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2271 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2272 if(!cId)
2273 return false;
2275 uint32 go_id = atol(cId);
2276 if(!go_id)
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2279 SetSentErrorMessage(true);
2280 return false;
2283 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2284 if(!gInfo)
2286 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2287 SetSentErrorMessage(true);
2288 return false;
2291 char* c_count = strtok(NULL, " ");
2292 int count = c_count ? atol(c_count) : 10;
2294 if(count < 0)
2295 return false;
2297 QueryResult *result;
2299 uint32 obj_count = 0;
2300 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2301 if(result)
2303 obj_count = (*result)[0].GetUInt32();
2304 delete result;
2307 if(m_session)
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));
2313 else
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));
2317 if (result)
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();
2328 if (m_session)
2329 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2330 else
2331 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2332 } while (result->NextRow());
2334 delete result;
2337 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2338 return true;
2341 bool ChatHandler::HandleNearObjectCommand(const char* args)
2343 float distance = (!*args) ? 10 : atol(args);
2344 uint32 count = 0;
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);
2353 if (result)
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);
2367 if(!gInfo)
2368 continue;
2370 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2372 ++count;
2373 } while (result->NextRow());
2375 delete result;
2378 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2379 return true;
2382 bool ChatHandler::HandleListCreatureCommand(const char* args)
2384 if(!*args)
2385 return false;
2387 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2388 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2389 if(!cId)
2390 return false;
2392 uint32 cr_id = atol(cId);
2393 if(!cr_id)
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2396 SetSentErrorMessage(true);
2397 return false;
2400 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2401 if(!cInfo)
2403 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2404 SetSentErrorMessage(true);
2405 return false;
2408 char* c_count = strtok(NULL, " ");
2409 int count = c_count ? atol(c_count) : 10;
2411 if(count < 0)
2412 return false;
2414 QueryResult *result;
2416 uint32 cr_count = 0;
2417 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2418 if(result)
2420 cr_count = (*result)[0].GetUInt32();
2421 delete result;
2424 if(m_session)
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));
2430 else
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));
2434 if (result)
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();
2445 if (m_session)
2446 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2447 else
2448 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2449 } while (result->NextRow());
2451 delete result;
2454 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2455 return true;
2458 bool ChatHandler::HandleLookupItemCommand(const char* args)
2460 if(!*args)
2461 return false;
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))
2468 return false;
2470 wstrToLower(wnamepart);
2472 uint32 counter = 0;
2474 // Search in `item_template`
2475 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2477 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2478 if(!pProto)
2479 continue;
2481 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2482 if ( loc_idx >= 0 )
2484 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2485 if (il)
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))
2493 if (m_session)
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2495 else
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2497 ++counter;
2498 continue;
2504 std::string name = pProto->Name1;
2505 if(name.empty())
2506 continue;
2508 if (Utf8FitTo(name, wnamepart))
2510 if (m_session)
2511 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2512 else
2513 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2514 ++counter;
2518 if (counter==0)
2519 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2521 return true;
2524 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2526 if(!*args)
2527 return false;
2529 std::string namepart = args;
2530 std::wstring wnamepart;
2532 if(!Utf8toWStr(namepart,wnamepart))
2533 return false;
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);
2544 if(set)
2546 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2547 std::string name = set->name[loc];
2548 if(name.empty())
2549 continue;
2551 if (!Utf8FitTo(name, wnamepart))
2553 loc = 0;
2554 for(; loc < MAX_LOCALE; ++loc)
2556 if(m_session && loc==m_session->GetSessionDbcLocale())
2557 continue;
2559 name = set->name[loc];
2560 if(name.empty())
2561 continue;
2563 if (Utf8FitTo(name, wnamepart))
2564 break;
2568 if(loc < MAX_LOCALE)
2570 // send item set in "id - [namedlink locale]" format
2571 if (m_session)
2572 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2573 else
2574 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2575 ++counter;
2579 if (counter == 0) // if counter == 0 then we found nth
2580 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2581 return true;
2584 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2586 if(!*args)
2587 return false;
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))
2596 return false;
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);
2607 if(skillInfo)
2609 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2610 std::string name = skillInfo->name[loc];
2611 if(name.empty())
2612 continue;
2614 if (!Utf8FitTo(name, wnamepart))
2616 loc = 0;
2617 for(; loc < MAX_LOCALE; ++loc)
2619 if(m_session && loc==m_session->GetSessionDbcLocale())
2620 continue;
2622 name = skillInfo->name[loc];
2623 if(name.empty())
2624 continue;
2626 if (Utf8FitTo(name, wnamepart))
2627 break;
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
2638 if (m_session)
2639 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2640 else
2641 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2643 ++counter;
2647 if (counter == 0) // if counter == 0 then we found nth
2648 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2649 return true;
2652 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2654 if(!*args)
2655 return false;
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))
2664 return false;
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);
2675 if(spellInfo)
2677 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2678 std::string name = spellInfo->SpellName[loc];
2679 if(name.empty())
2680 continue;
2682 if (!Utf8FitTo(name, wnamepart))
2684 loc = 0;
2685 for(; loc < MAX_LOCALE; ++loc)
2687 if(m_session && loc==m_session->GetSessionDbcLocale())
2688 continue;
2690 name = spellInfo->SpellName[loc];
2691 if(name.empty())
2692 continue;
2694 if (Utf8FitTo(name, wnamepart))
2695 break;
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;
2716 if (m_session)
2717 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2718 else
2719 ss << id << " - " << name;
2721 // include rank in link name
2722 if(rank)
2723 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2725 if (m_session)
2726 ss << " " << localeNames[loc] << "]|h|r";
2727 else
2728 ss << " " << localeNames[loc];
2730 if(talent)
2731 ss << GetMangosString(LANG_TALENT);
2732 if(passive)
2733 ss << GetMangosString(LANG_PASSIVE);
2734 if(learn)
2735 ss << GetMangosString(LANG_LEARN);
2736 if(known)
2737 ss << GetMangosString(LANG_KNOWN);
2738 if(active)
2739 ss << GetMangosString(LANG_ACTIVE);
2741 SendSysMessage(ss.str().c_str());
2743 ++counter;
2747 if (counter == 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2749 return true;
2752 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2754 if(!*args)
2755 return false;
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))
2765 return false;
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();
2777 if ( loc_idx >= 0 )
2779 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2780 if (il)
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 = "";
2790 if(target)
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);
2798 else
2799 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2801 else if(status == QUEST_STATUS_INCOMPLETE)
2802 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2805 if (m_session)
2806 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2807 else
2808 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2809 ++counter;
2810 continue;
2816 std::string title = qinfo->GetTitle();
2817 if(title.empty())
2818 continue;
2820 if (Utf8FitTo(title, wnamepart))
2822 char const* statusStr = "";
2824 if(target)
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);
2832 else
2833 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2835 else if(status == QUEST_STATUS_INCOMPLETE)
2836 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2839 if (m_session)
2840 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2841 else
2842 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2844 ++counter;
2848 if (counter==0)
2849 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2851 return true;
2854 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2856 if (!*args)
2857 return false;
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))
2864 return false;
2866 wstrToLower (wnamepart);
2868 uint32 counter = 0;
2870 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2872 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2873 if(!cInfo)
2874 continue;
2876 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2877 if (loc_idx >= 0)
2879 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2880 if (cl)
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))
2888 if (m_session)
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2890 else
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2892 ++counter;
2893 continue;
2899 std::string name = cInfo->Name;
2900 if (name.empty ())
2901 continue;
2903 if (Utf8FitTo(name, wnamepart))
2905 if (m_session)
2906 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2907 else
2908 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2909 ++counter;
2913 if (counter==0)
2914 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2916 return true;
2919 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2921 if(!*args)
2922 return false;
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))
2929 return false;
2931 wstrToLower(wnamepart);
2933 uint32 counter = 0;
2935 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2937 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2938 if(!gInfo)
2939 continue;
2941 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2942 if ( loc_idx >= 0 )
2944 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2945 if (gl)
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))
2953 if (m_session)
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2955 else
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2957 ++counter;
2958 continue;
2964 std::string name = gInfo->name;
2965 if(name.empty())
2966 continue;
2968 if(Utf8FitTo(name, wnamepart))
2970 if (m_session)
2971 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2972 else
2973 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2974 ++counter;
2978 if(counter==0)
2979 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2981 return true;
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)
2995 if (!*args)
2996 return false;
2998 char *lname = strtok ((char*)args, " ");
2999 char *gname = strtok (NULL, "");
3001 if (!lname)
3002 return false;
3004 if (!gname)
3006 SendSysMessage (LANG_INSERT_GUILD_NAME);
3007 SetSentErrorMessage (true);
3008 return false;
3011 std::string guildname = gname;
3013 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3014 if (!player)
3016 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3017 SetSentErrorMessage (true);
3018 return false;
3021 if (player->GetGuildId())
3023 SendSysMessage (LANG_PLAYER_IN_GUILD);
3024 return true;
3027 Guild *guild = new Guild;
3028 if (!guild->create (player->GetGUID (),guildname))
3030 delete guild;
3031 SendSysMessage (LANG_GUILD_NOT_CREATED);
3032 SetSentErrorMessage (true);
3033 return false;
3036 objmgr.AddGuild (guild);
3037 return true;
3040 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3042 if (!*args)
3043 return false;
3045 char* par1 = strtok ((char*)args, " ");
3046 char* par2 = strtok (NULL, "");
3047 if(!par1 || !par2)
3048 return false;
3050 std::string glName = par2;
3051 Guild* targetGuild = objmgr.GetGuildByName (glName);
3052 if (!targetGuild)
3053 return false;
3055 std::string plName = par1;
3056 if (!normalizePlayerName (plName))
3058 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3059 SetSentErrorMessage (true);
3060 return false;
3063 uint64 plGuid = 0;
3064 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3065 plGuid = targetPlayer->GetGUID ();
3066 else
3067 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3069 if (!plGuid)
3070 false;
3072 // player's guild membership checked in AddMember before add
3073 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3074 return false;
3076 return true;
3079 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3081 if (!*args)
3082 return false;
3084 char* par1 = strtok ((char*)args, " ");
3085 if(!par1)
3086 return false;
3088 std::string plName = par1;
3089 if (!normalizePlayerName (plName))
3091 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3092 SetSentErrorMessage (true);
3093 return false;
3096 uint64 plGuid = 0;
3097 uint32 glId = 0;
3098 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3100 plGuid = targetPlayer->GetGUID ();
3101 glId = targetPlayer->GetGuildId ();
3103 else
3105 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3106 glId = Player::GetGuildIdFromDB (plGuid);
3109 if (!plGuid || !glId)
3110 return false;
3112 Guild* targetGuild = objmgr.GetGuildById (glId);
3113 if (!targetGuild)
3114 return false;
3116 targetGuild->DelMember (plGuid);
3118 return true;
3121 bool ChatHandler::HandleGuildRankCommand(const char *args)
3123 if (!*args)
3124 return false;
3126 char* par1 = strtok ((char*)args, " ");
3127 char* par2 = strtok (NULL, " ");
3128 if (!par1 || !par2)
3129 return false;
3130 std::string plName = par1;
3131 if (!normalizePlayerName (plName))
3133 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3134 SetSentErrorMessage (true);
3135 return false;
3138 uint64 plGuid = 0;
3139 uint32 glId = 0;
3140 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3142 plGuid = targetPlayer->GetGUID ();
3143 glId = targetPlayer->GetGuildId ();
3145 else
3147 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3148 glId = Player::GetGuildIdFromDB (plGuid);
3151 if (!plGuid || !glId)
3152 return false;
3154 Guild* targetGuild = objmgr.GetGuildById (glId);
3155 if (!targetGuild)
3156 return false;
3158 uint32 newrank = uint32 (atoi (par2));
3159 if (newrank > targetGuild->GetLowestRank ())
3160 return false;
3162 targetGuild->ChangeRank (plGuid,newrank);
3164 return true;
3167 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3169 if (!*args)
3170 return false;
3172 char* par1 = strtok ((char*)args, " ");
3173 if (!par1)
3174 return false;
3176 std::string gld = par1;
3178 Guild* targetGuild = objmgr.GetGuildByName (gld);
3179 if (!targetGuild)
3180 return false;
3182 targetGuild->Disband ();
3184 return true;
3187 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3189 Unit* pUnit = getSelectedUnit();
3191 if(!pUnit)
3193 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3194 SetSentErrorMessage(true);
3195 return false;
3198 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3200 return true;
3203 // FIX-ME!!!
3205 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3207 /*if (!*args)
3208 return false;
3210 uint64 guid = m_session->GetPlayer()->GetSelection();
3211 if (guid == 0)
3213 SendSysMessage(LANG_NO_SELECTION);
3214 return true;
3217 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3219 if(!pCreature)
3221 SendSysMessage(LANG_SELECT_CREATURE);
3222 return true;
3225 char* pSlotID = strtok((char*)args, " ");
3226 if (!pSlotID)
3227 return false;
3229 char* pItemID = strtok(NULL, " ");
3230 if (!pItemID)
3231 return false;
3233 uint32 ItemID = atoi(pItemID);
3234 uint32 SlotID = atoi(pSlotID);
3236 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3238 bool added = false;
3239 if(tmpItem)
3241 switch(SlotID)
3243 case 1:
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3245 added = true;
3246 break;
3247 case 2:
3248 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3249 added = true;
3250 break;
3251 case 3:
3252 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3253 added = true;
3254 break;
3255 default:
3256 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3257 added = false;
3258 break;
3260 if(added)
3262 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3265 else
3267 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3268 return true;
3271 return true;
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);
3282 return false;
3285 if( target->isAlive() )
3287 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3290 return true;
3293 bool ChatHandler::HandleDamageCommand(const char * args)
3295 if (!*args)
3296 return false;
3298 Unit* target = getSelectedUnit();
3300 if(!target || !m_session->GetPlayer()->GetSelection())
3302 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3303 SetSentErrorMessage(true);
3304 return false;
3307 if( !target->isAlive() )
3308 return true;
3310 char* damageStr = strtok((char*)args, " ");
3311 if(!damageStr)
3312 return false;
3314 int32 damage = atoi((char*)damageStr);
3315 if(damage <=0)
3316 return true;
3318 char* schoolStr = strtok((char*)NULL, " ");
3320 // flat melee damage without resistence/etc reduction
3321 if(!schoolStr)
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);
3325 return true;
3328 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3329 if(school >= MAX_SPELL_SCHOOL)
3330 return false;
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
3340 if(!spellStr)
3342 uint32 absorb = 0;
3343 uint32 resist = 0;
3345 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3347 if (damage <= absorb + resist)
3348 return true;
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);
3354 return true;
3357 // non-melee damage
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))
3362 return false;
3364 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3365 return true;
3368 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3370 if (!*args)
3371 return false;
3373 Player *target = getSelectedPlayer();
3374 if(!target)
3376 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3377 SetSentErrorMessage(true);
3378 return false;
3381 int32 amount = (uint32)atoi(args);
3383 target->ModifyArenaPoints(amount);
3385 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3387 return true;
3390 bool ChatHandler::HandleReviveCommand(const char* args)
3392 Player* SelectedPlayer = NULL;
3394 if (*args)
3396 std::string name = args;
3397 if(!normalizePlayerName(name))
3399 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3400 SetSentErrorMessage(true);
3401 return false;
3404 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3406 else
3407 SelectedPlayer = getSelectedPlayer();
3409 if(!SelectedPlayer)
3411 SendSysMessage(LANG_NO_CHAR_SELECTED);
3412 SetSentErrorMessage(true);
3413 return false;
3416 SelectedPlayer->ResurrectPlayer(0.5f);
3417 SelectedPlayer->SpawnCorpseBones();
3418 SelectedPlayer->SaveToDB();
3419 return true;
3422 bool ChatHandler::HandleAuraCommand(const char* args)
3424 char* px = strtok((char*)args, " ");
3425 if (!px)
3426 return false;
3428 Unit *target = getSelectedUnit();
3429 if(!target)
3431 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3432 SetSentErrorMessage(true);
3433 return false;
3436 uint32 spellID = (uint32)atoi(px);
3437 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3438 if(spellInfo)
3440 for(uint32 i = 0;i<3;i++)
3442 uint8 eff = spellInfo->Effect[i];
3443 if (eff>=TOTAL_SPELL_EFFECTS)
3444 continue;
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);
3455 return true;
3458 bool ChatHandler::HandleUnAuraCommand(const char* args)
3460 char* px = strtok((char*)args, " ");
3461 if (!px)
3462 return false;
3464 Unit *target = getSelectedUnit();
3465 if(!target)
3467 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3468 SetSentErrorMessage(true);
3469 return false;
3472 std::string argstr = args;
3473 if (argstr == "all")
3475 target->RemoveAllAuras();
3476 return true;
3479 uint32 spellID = (uint32)atoi(px);
3480 target->RemoveAurasDueToSpell(spellID);
3482 return true;
3485 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3487 if(!*args)
3488 return false;
3490 char* px = strtok((char*)args, " ");
3491 if (!px)
3492 return false;
3494 uint32 g_id = (uint32)atoi(px);
3496 uint32 g_team;
3498 char* px2 = strtok(NULL, " ");
3500 if (!px2)
3501 g_team = 0;
3502 else if (strncmp(px2,"horde",6)==0)
3503 g_team = HORDE;
3504 else if (strncmp(px2,"alliance",9)==0)
3505 g_team = ALLIANCE;
3506 else
3507 return false;
3509 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3511 if(!graveyard )
3513 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3514 SetSentErrorMessage(true);
3515 return false;
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);
3527 return false;
3530 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3532 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3533 SetSentErrorMessage(true);
3534 return false;
3537 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3538 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3539 else
3540 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3542 return true;
3545 bool ChatHandler::HandleNearGraveCommand(const char* args)
3547 uint32 g_team;
3549 size_t argslen = strlen(args);
3551 if(!*args)
3552 g_team = 0;
3553 else if (strncmp((char*)args,"horde",argslen)==0)
3554 g_team = HORDE;
3555 else if (strncmp((char*)args,"alliance",argslen)==0)
3556 g_team = ALLIANCE;
3557 else
3558 return false;
3560 Player* player = m_session->GetPlayer();
3562 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3563 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3565 if(graveyard)
3567 uint32 g_id = graveyard->ID;
3569 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3570 if (!data)
3572 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3573 SetSentErrorMessage(true);
3574 return false;
3577 g_team = data->team;
3579 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3581 if(g_team == 0)
3582 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3583 else if(g_team == HORDE)
3584 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3585 else if(g_team == ALLIANCE)
3586 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3588 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3590 else
3592 std::string team_name;
3594 if(g_team == 0)
3595 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3596 else if(g_team == HORDE)
3597 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3598 else if(g_team == ALLIANCE)
3599 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3601 if(g_team == ~uint32(0))
3602 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3603 else
3604 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3607 return true;
3610 //play npc emote
3611 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3613 uint32 emote = atoi((char*)args);
3615 Creature* target = getSelectedCreature();
3616 if(!target)
3618 SendSysMessage(LANG_SELECT_CREATURE);
3619 SetSentErrorMessage(true);
3620 return false;
3623 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3625 return true;
3628 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3630 Creature* target = getSelectedCreature();
3632 if(!target)
3634 SendSysMessage(LANG_SELECT_CREATURE);
3635 SetSentErrorMessage(true);
3636 return false;
3639 uint32 faction = target->getFaction();
3640 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3641 uint32 displayid = target->GetDisplayId();
3642 uint32 nativeid = target->GetNativeDisplayId();
3643 uint32 Entry = target->GetEntry();
3644 CreatureInfo const* cInfo = target->GetCreatureInfo();
3646 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3647 if(curRespawnDelay < 0)
3648 curRespawnDelay = 0;
3649 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3650 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3652 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3653 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3654 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3655 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3656 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3657 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3658 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3659 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3661 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3663 SendSysMessage(LANG_NPCINFO_VENDOR);
3665 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3667 SendSysMessage(LANG_NPCINFO_TRAINER);
3670 return true;
3673 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3675 if (!*args)
3676 return false;
3678 int flag = atoi((char*)args);
3680 Player *chr = getSelectedPlayer();
3681 if (chr == NULL)
3683 SendSysMessage(LANG_NO_CHAR_SELECTED);
3684 SetSentErrorMessage(true);
3685 return false;
3688 if (flag != 0)
3690 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3691 if (needReportToTarget(chr))
3692 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetName());
3694 else
3696 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3697 if (needReportToTarget(chr))
3698 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetName());
3701 for (uint8 i=0; i<128; i++)
3703 if (flag != 0)
3705 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3707 else
3709 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3713 return true;
3716 bool ChatHandler::HandleHoverCommand(const char* args)
3718 char* px = strtok((char*)args, " ");
3719 uint32 flag;
3720 if (!px)
3721 flag = 1;
3722 else
3723 flag = atoi(px);
3725 m_session->GetPlayer()->SetHover(flag);
3727 if (flag)
3728 SendSysMessage(LANG_HOVER_ENABLED);
3729 else
3730 SendSysMessage(LANG_HOVER_DISABLED);
3732 return true;
3735 bool ChatHandler::HandleLevelUpCommand(const char* args)
3737 char* px = strtok((char*)args, " ");
3738 char* py = strtok((char*)NULL, " ");
3740 // command format parsing
3741 char* pname = (char*)NULL;
3742 int addlevel = 1;
3744 if(px && py) // .levelup name level
3746 addlevel = atoi(py);
3747 pname = px;
3749 else if(px && !py) // .levelup name OR .levelup level
3751 if(isalpha(px[0])) // .levelup name
3752 pname = px;
3753 else // .levelup level
3754 addlevel = atoi(px);
3756 // else .levelup - nothing do for preparing
3758 // player
3759 Player *chr = NULL;
3760 uint64 chr_guid = 0;
3762 std::string name;
3764 if(pname) // player by name
3766 name = pname;
3767 if(!normalizePlayerName(name))
3769 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3770 SetSentErrorMessage(true);
3771 return false;
3774 chr = objmgr.GetPlayer(name.c_str());
3775 if(!chr) // not in game
3777 chr_guid = objmgr.GetPlayerGUIDByName(name);
3778 if (chr_guid == 0)
3780 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3781 SetSentErrorMessage(true);
3782 return false;
3786 else // player by selection
3788 chr = getSelectedPlayer();
3790 if (chr == NULL)
3792 SendSysMessage(LANG_NO_CHAR_SELECTED);
3793 SetSentErrorMessage(true);
3794 return false;
3797 name = chr->GetName();
3800 assert(chr || chr_guid);
3802 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3803 int32 newlevel = oldlevel + addlevel;
3804 if(newlevel < 1)
3805 newlevel = 1;
3806 if(newlevel > 255) // hardcoded maximum level
3807 newlevel = 255;
3809 if(chr)
3811 chr->GiveLevel(newlevel);
3812 chr->InitTalentForLevel();
3813 chr->SetUInt32Value(PLAYER_XP,0);
3815 if(oldlevel == newlevel)
3816 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3817 else
3818 if(oldlevel < newlevel)
3819 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3820 else
3821 if(oldlevel > newlevel)
3822 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3824 else
3826 // update level and XP at level, all other will be updated at loading
3827 Tokens values;
3828 Player::LoadValuesArrayFromDB(values,chr_guid);
3829 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3830 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3831 Player::SaveValuesArrayInDB(values,chr_guid);
3834 if(m_session->GetPlayer() != chr) // including chr==NULL
3835 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3836 return true;
3839 bool ChatHandler::HandleShowAreaCommand(const char* args)
3841 if (!*args)
3842 return false;
3844 int area = atoi((char*)args);
3846 Player *chr = getSelectedPlayer();
3847 if (chr == NULL)
3849 SendSysMessage(LANG_NO_CHAR_SELECTED);
3850 SetSentErrorMessage(true);
3851 return false;
3854 int offset = area / 32;
3855 uint32 val = (uint32)(1 << (area % 32));
3857 if(offset >= 128)
3859 SendSysMessage(LANG_BAD_VALUE);
3860 SetSentErrorMessage(true);
3861 return false;
3864 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3865 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3867 SendSysMessage(LANG_EXPLORE_AREA);
3868 return true;
3871 bool ChatHandler::HandleHideAreaCommand(const char* args)
3873 if (!*args)
3874 return false;
3876 int area = atoi((char*)args);
3878 Player *chr = getSelectedPlayer();
3879 if (chr == NULL)
3881 SendSysMessage(LANG_NO_CHAR_SELECTED);
3882 SetSentErrorMessage(true);
3883 return false;
3886 int offset = area / 32;
3887 uint32 val = (uint32)(1 << (area % 32));
3889 if(offset >= 128)
3891 SendSysMessage(LANG_BAD_VALUE);
3892 SetSentErrorMessage(true);
3893 return false;
3896 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3897 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3899 SendSysMessage(LANG_UNEXPLORE_AREA);
3900 return true;
3903 bool ChatHandler::HandleUpdate(const char* args)
3905 if(!*args)
3906 return false;
3908 uint32 updateIndex;
3909 uint32 value;
3911 char* pUpdateIndex = strtok((char*)args, " ");
3913 Unit* chr = getSelectedUnit();
3914 if (chr == NULL)
3916 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3917 SetSentErrorMessage(true);
3918 return false;
3921 if(!pUpdateIndex)
3923 return true;
3925 updateIndex = atoi(pUpdateIndex);
3926 //check updateIndex
3927 if(chr->GetTypeId() == TYPEID_PLAYER)
3929 if (updateIndex>=PLAYER_END) return true;
3931 else
3933 if (updateIndex>=UNIT_END) return true;
3936 char* pvalue = strtok(NULL, " ");
3937 if (!pvalue)
3939 value=chr->GetUInt32Value(updateIndex);
3941 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3942 return true;
3945 value=atoi(pvalue);
3947 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3949 chr->SetUInt32Value(updateIndex,value);
3951 return true;
3954 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3956 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3958 return true;
3961 bool ChatHandler::HandleChangeWeather(const char* args)
3963 if(!*args)
3964 return false;
3966 //Weather is OFF
3967 if (!sWorld.getConfig(CONFIG_WEATHER))
3969 SendSysMessage(LANG_WEATHER_DISABLED);
3970 SetSentErrorMessage(true);
3971 return false;
3974 //*Change the weather of a cell
3975 char* px = strtok((char*)args, " ");
3976 char* py = strtok(NULL, " ");
3978 if (!px || !py)
3979 return false;
3981 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3982 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3984 Player *player = m_session->GetPlayer();
3985 uint32 zoneid = player->GetZoneId();
3987 Weather* wth = sWorld.FindWeather(zoneid);
3989 if(!wth)
3990 wth = sWorld.AddWeather(zoneid);
3991 if(!wth)
3993 SendSysMessage(LANG_NO_WEATHER);
3994 SetSentErrorMessage(true);
3995 return false;
3998 wth->SetWeather(WeatherType(type), grade);
4000 return true;
4003 bool ChatHandler::HandleSetValue(const char* args)
4005 if(!*args)
4006 return false;
4008 char* px = strtok((char*)args, " ");
4009 char* py = strtok(NULL, " ");
4010 char* pz = strtok(NULL, " ");
4012 if (!px || !py)
4013 return false;
4015 Unit* target = getSelectedUnit();
4016 if(!target)
4018 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4019 SetSentErrorMessage(true);
4020 return false;
4023 uint64 guid = target->GetGUID();
4025 uint32 Opcode = (uint32)atoi(px);
4026 if(Opcode >= target->GetValuesCount())
4028 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4029 return false;
4031 uint32 iValue;
4032 float fValue;
4033 bool isint32 = true;
4034 if(pz)
4035 isint32 = (bool)atoi(pz);
4036 if(isint32)
4038 iValue = (uint32)atoi(py);
4039 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4040 target->SetUInt32Value( Opcode , iValue );
4041 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4043 else
4045 fValue = (float)atof(py);
4046 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4047 target->SetFloatValue( Opcode , fValue );
4048 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4051 return true;
4054 bool ChatHandler::HandleGetValue(const char* args)
4056 if(!*args)
4057 return false;
4059 char* px = strtok((char*)args, " ");
4060 char* pz = strtok(NULL, " ");
4062 if (!px)
4063 return false;
4065 Unit* target = getSelectedUnit();
4066 if(!target)
4068 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4069 SetSentErrorMessage(true);
4070 return false;
4073 uint64 guid = target->GetGUID();
4075 uint32 Opcode = (uint32)atoi(px);
4076 if(Opcode >= target->GetValuesCount())
4078 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4079 return false;
4081 uint32 iValue;
4082 float fValue;
4083 bool isint32 = true;
4084 if(pz)
4085 isint32 = (bool)atoi(pz);
4087 if(isint32)
4089 iValue = target->GetUInt32Value( Opcode );
4090 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4091 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4093 else
4095 fValue = target->GetFloatValue( Opcode );
4096 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4097 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4100 return true;
4103 bool ChatHandler::HandleSet32Bit(const char* args)
4105 if(!*args)
4106 return false;
4108 char* px = strtok((char*)args, " ");
4109 char* py = strtok(NULL, " ");
4111 if (!px || !py)
4112 return false;
4114 uint32 Opcode = (uint32)atoi(px);
4115 uint32 Value = (uint32)atoi(py);
4116 if (Value > 32) //uint32 = 32 bits
4117 return false;
4119 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4121 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4123 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4124 return true;
4127 bool ChatHandler::HandleMod32Value(const char* args)
4129 if(!*args)
4130 return false;
4132 char* px = strtok((char*)args, " ");
4133 char* py = strtok(NULL, " ");
4135 if (!px || !py)
4136 return false;
4138 uint32 Opcode = (uint32)atoi(px);
4139 int Value = atoi(py);
4141 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4143 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4144 return false;
4147 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4149 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4151 CurrentValue += Value;
4152 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4154 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4156 return true;
4159 bool ChatHandler::HandleAddTeleCommand(const char * args)
4161 if(!*args)
4162 return false;
4164 Player *player=m_session->GetPlayer();
4165 if (!player)
4166 return false;
4168 std::string name = args;
4170 if(objmgr.GetGameTele(name))
4172 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4173 SetSentErrorMessage(true);
4174 return false;
4177 GameTele tele;
4178 tele.position_x = player->GetPositionX();
4179 tele.position_y = player->GetPositionY();
4180 tele.position_z = player->GetPositionZ();
4181 tele.orientation = player->GetOrientation();
4182 tele.mapId = player->GetMapId();
4183 tele.name = name;
4185 if(objmgr.AddGameTele(tele))
4187 SendSysMessage(LANG_COMMAND_TP_ADDED);
4189 else
4191 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4192 SetSentErrorMessage(true);
4193 return false;
4196 return true;
4199 bool ChatHandler::HandleDelTeleCommand(const char * args)
4201 if(!*args)
4202 return false;
4204 std::string name = args;
4206 if(!objmgr.DeleteGameTele(name))
4208 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4209 SetSentErrorMessage(true);
4210 return false;
4213 SendSysMessage(LANG_COMMAND_TP_DELETED);
4214 return true;
4217 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4219 Unit *unit = getSelectedUnit();
4220 if(!unit)
4222 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4223 SetSentErrorMessage(true);
4224 return false;
4227 char const* talentStr = GetMangosString(LANG_TALENT);
4228 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4230 Unit::AuraMap const& uAuras = unit->GetAuras();
4231 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4232 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4234 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4235 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4236 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4237 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4238 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4239 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4241 for (int i = 0; i < TOTAL_AURAS; i++)
4243 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4244 if (uAuraList.empty()) continue;
4245 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4246 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4248 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4249 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4250 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4251 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4254 return true;
4257 bool ChatHandler::HandleResetHonorCommand (const char * args)
4259 char* pName = strtok((char*)args, "");
4260 Player *player = NULL;
4261 if (pName)
4263 std::string name = pName;
4264 if(!normalizePlayerName(name))
4266 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4267 SetSentErrorMessage(true);
4268 return false;
4271 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4272 player = objmgr.GetPlayer(guid);
4274 else
4275 player = getSelectedPlayer();
4277 if(!player)
4279 SendSysMessage(LANG_NO_CHAR_SELECTED);
4280 return true;
4283 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4284 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4285 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4286 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4287 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4289 return true;
4292 static bool HandleResetStatsOrLevelHelper(Player* player)
4294 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4295 if(!info) return false;
4297 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4298 if(!cEntry)
4300 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4301 return false;
4304 uint8 powertype = cEntry->powerType;
4306 uint32 unitfield;
4307 if(powertype == POWER_RAGE)
4308 unitfield = 0x1100EE00;
4309 else if(powertype == POWER_ENERGY)
4310 unitfield = 0x00000000;
4311 else if(powertype == POWER_MANA)
4312 unitfield = 0x0000EE00;
4313 else
4315 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4316 return false;
4319 // reset m_form if no aura
4320 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4321 player->m_form = FORM_NONE;
4323 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4324 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4326 player->setFactionForRace(player->getRace());
4328 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4330 // reset only if player not in some form;
4331 if(player->m_form==FORM_NONE)
4333 switch(player->getGender())
4335 case GENDER_FEMALE:
4336 player->SetDisplayId(info->displayId_f);
4337 player->SetNativeDisplayId(info->displayId_f);
4338 break;
4339 case GENDER_MALE:
4340 player->SetDisplayId(info->displayId_m);
4341 player->SetNativeDisplayId(info->displayId_m);
4342 break;
4343 default:
4344 break;
4348 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4349 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4350 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_PVP );
4351 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4353 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4355 //-1 is default value
4356 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4358 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4359 return true;
4362 bool ChatHandler::HandleResetLevelCommand(const char * args)
4364 char* pName = strtok((char*)args, "");
4365 Player *player = NULL;
4366 if (pName)
4368 std::string name = pName;
4369 if(!normalizePlayerName(name))
4371 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4372 SetSentErrorMessage(true);
4373 return false;
4376 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4377 player = objmgr.GetPlayer(guid);
4379 else
4380 player = getSelectedPlayer();
4382 if(!player)
4384 SendSysMessage(LANG_NO_CHAR_SELECTED);
4385 SetSentErrorMessage(true);
4386 return false;
4389 if(!HandleResetStatsOrLevelHelper(player))
4390 return false;
4392 player->SetLevel(1);
4393 player->InitStatsForLevel(true);
4394 player->InitTaxiNodesForLevel();
4395 player->InitGlyphsForLevel();
4396 player->InitTalentForLevel();
4397 player->SetUInt32Value(PLAYER_XP,0);
4399 // reset level to summoned pet
4400 Pet* pet = player->GetPet();
4401 if(pet && pet->getPetType()==SUMMON_PET)
4402 pet->InitStatsForLevel(1);
4404 return true;
4407 bool ChatHandler::HandleResetStatsCommand(const char * args)
4409 char* pName = strtok((char*)args, "");
4410 Player *player = NULL;
4411 if (pName)
4413 std::string name = pName;
4414 if(!normalizePlayerName(name))
4416 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4417 SetSentErrorMessage(true);
4418 return false;
4421 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4422 player = objmgr.GetPlayer(guid);
4424 else
4425 player = getSelectedPlayer();
4427 if(!player)
4429 SendSysMessage(LANG_NO_CHAR_SELECTED);
4430 SetSentErrorMessage(true);
4431 return false;
4434 if(!HandleResetStatsOrLevelHelper(player))
4435 return false;
4437 player->InitStatsForLevel(true);
4438 player->InitTaxiNodesForLevel();
4439 player->InitGlyphsForLevel();
4440 player->InitTalentForLevel();
4442 return true;
4445 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4447 char* pName = strtok((char*)args, "");
4448 Player *player = NULL;
4449 uint64 playerGUID = 0;
4450 if (pName)
4452 std::string name = pName;
4454 if(!normalizePlayerName(name))
4456 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4457 SetSentErrorMessage(true);
4458 return false;
4461 player = objmgr.GetPlayer(name.c_str());
4462 if(!player)
4463 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4465 else
4466 player = getSelectedPlayer();
4468 if(!player && !playerGUID)
4470 SendSysMessage(LANG_NO_CHAR_SELECTED);
4471 SetSentErrorMessage(true);
4472 return false;
4475 if(player)
4477 player->resetSpells();
4479 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4481 if(m_session->GetPlayer()!=player)
4482 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4484 else
4486 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4487 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4490 return true;
4493 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4495 char* pName = strtok((char*)args, "");
4496 Player *player = NULL;
4497 uint64 playerGUID = 0;
4498 if (pName)
4500 std::string name = pName;
4501 if(!normalizePlayerName(name))
4503 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4504 SetSentErrorMessage(true);
4505 return false;
4508 player = objmgr.GetPlayer(name.c_str());
4509 if(!player)
4510 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4512 else
4513 player = getSelectedPlayer();
4515 if(!player && !playerGUID)
4517 SendSysMessage(LANG_NO_CHAR_SELECTED);
4518 SetSentErrorMessage(true);
4519 return false;
4522 if(player)
4524 player->resetTalents(true);
4526 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4528 if(m_session->GetPlayer()!=player)
4529 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4531 else
4533 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4534 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4537 return true;
4540 bool ChatHandler::HandleResetAllCommand(const char * args)
4542 if(!*args)
4543 return false;
4545 std::string casename = args;
4547 AtLoginFlags atLogin;
4549 // Command specially created as single command to prevent using short case names
4550 if(casename=="spells")
4552 atLogin = AT_LOGIN_RESET_SPELLS;
4553 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4555 else if(casename=="talents")
4557 atLogin = AT_LOGIN_RESET_TALENTS;
4558 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4560 else
4562 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4563 SetSentErrorMessage(true);
4564 return false;
4567 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4568 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4569 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4570 itr->second->SetAtLoginFlag(atLogin);
4572 return true;
4575 bool ChatHandler::HandleShutDownCommand(const char* args)
4577 if(!*args)
4578 return false;
4580 if(std::string(args)=="cancel")
4582 sWorld.ShutdownCancel();
4584 else
4586 int32 time = atoi(args);
4588 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4589 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4590 return false;
4592 sWorld.ShutdownServ(time);
4594 return true;
4597 bool ChatHandler::HandleRestartCommand(const char* args)
4599 if(!*args)
4600 return false;
4602 if(std::string(args)=="cancel")
4604 sWorld.ShutdownCancel();
4606 else
4608 int32 time = atoi(args);
4610 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4611 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4612 return false;
4614 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4616 return true;
4619 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4621 if(!*args)
4622 return false;
4624 if(std::string(args)=="cancel")
4626 sWorld.ShutdownCancel();
4628 else
4630 int32 time = atoi(args);
4632 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4633 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4634 return false;
4636 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4638 return true;
4641 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4643 if(!*args)
4644 return false;
4646 if(std::string(args)=="cancel")
4648 sWorld.ShutdownCancel();
4650 else
4652 int32 time = atoi(args);
4654 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4655 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4656 return false;
4658 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4660 return true;
4663 bool ChatHandler::HandleAddQuest(const char* args)
4665 Player* player = getSelectedPlayer();
4666 if(!player)
4668 SendSysMessage(LANG_NO_CHAR_SELECTED);
4669 SetSentErrorMessage(true);
4670 return false;
4673 // .addquest #entry'
4674 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4675 char* cId = extractKeyFromLink((char*)args,"Hquest");
4676 if(!cId)
4677 return false;
4679 uint32 entry = atol(cId);
4681 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4683 if(!pQuest)
4685 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4686 SetSentErrorMessage(true);
4687 return false;
4690 // check item starting quest (it can work incorrectly if added without item in inventory)
4691 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4693 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4694 if (!pProto)
4695 continue;
4697 if (pProto->StartQuest == entry)
4699 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4700 SetSentErrorMessage(true);
4701 return false;
4705 // ok, normal (creature/GO starting) quest
4706 if( player->CanAddQuest( pQuest, true ) )
4708 player->AddQuest( pQuest, NULL );
4710 if ( player->CanCompleteQuest( entry ) )
4711 player->CompleteQuest( entry );
4714 return true;
4717 bool ChatHandler::HandleRemoveQuest(const char* args)
4719 Player* player = getSelectedPlayer();
4720 if(!player)
4722 SendSysMessage(LANG_NO_CHAR_SELECTED);
4723 SetSentErrorMessage(true);
4724 return false;
4727 // .removequest #entry'
4728 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4729 char* cId = extractKeyFromLink((char*)args,"Hquest");
4730 if(!cId)
4731 return false;
4733 uint32 entry = atol(cId);
4735 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4737 if(!pQuest)
4739 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4740 SetSentErrorMessage(true);
4741 return false;
4744 // remove all quest entries for 'entry' from quest log
4745 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4747 uint32 quest = player->GetQuestSlotQuestId(slot);
4748 if(quest==entry)
4750 player->SetQuestSlot(slot,0);
4752 // we ignore unequippable quest items in this case, its' still be equipped
4753 player->TakeQuestSourceItem( quest, false );
4757 // set quest status to not started (will updated in DB at next save)
4758 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4760 // reset rewarded for restart repeatable quest
4761 player->getQuestStatusMap()[entry].m_rewarded = false;
4763 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4764 return true;
4767 bool ChatHandler::HandleCompleteQuest(const char* args)
4769 Player* player = getSelectedPlayer();
4770 if(!player)
4772 SendSysMessage(LANG_NO_CHAR_SELECTED);
4773 SetSentErrorMessage(true);
4774 return false;
4777 // .quest complete #entry
4778 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4779 char* cId = extractKeyFromLink((char*)args,"Hquest");
4780 if(!cId)
4781 return false;
4783 uint32 entry = atol(cId);
4785 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4787 // If player doesn't have the quest
4788 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4790 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4791 SetSentErrorMessage(true);
4792 return false;
4795 // Add quest items for quests that require items
4796 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4798 uint32 id = pQuest->ReqItemId[x];
4799 uint32 count = pQuest->ReqItemCount[x];
4800 if(!id || !count)
4801 continue;
4803 uint32 curItemCount = player->GetItemCount(id,true);
4805 ItemPosCountVec dest;
4806 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4807 if( msg == EQUIP_ERR_OK )
4809 Item* item = player->StoreNewItem( dest, id, true);
4810 player->SendNewItem(item,count-curItemCount,true,false);
4814 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4815 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4817 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4818 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4820 if(uint32 spell_id = pQuest->ReqSpell[i])
4822 for(uint16 z = 0; z < creaturecount; ++z)
4823 player->CastedCreatureOrGO(creature,0,spell_id);
4825 else if(creature > 0)
4827 for(uint16 z = 0; z < creaturecount; ++z)
4828 player->KilledMonster(creature,0);
4830 else if(creature < 0)
4832 for(uint16 z = 0; z < creaturecount; ++z)
4833 player->CastedCreatureOrGO(creature,0,0);
4837 // If the quest requires reputation to complete
4838 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4840 uint32 repValue = pQuest->GetRepObjectiveValue();
4841 uint32 curRep = player->GetReputation(repFaction);
4842 if(curRep < repValue)
4844 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4845 player->SetFactionReputation(factionEntry,repValue);
4849 // If the quest requires money
4850 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4851 if(ReqOrRewMoney < 0)
4852 player->ModifyMoney(-ReqOrRewMoney);
4854 player->CompleteQuest(entry);
4855 return true;
4858 bool ChatHandler::HandleBanAccountCommand(const char* args)
4860 return HandleBanHelper(BAN_ACCOUNT,args);
4863 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4865 return HandleBanHelper(BAN_CHARACTER,args);
4868 bool ChatHandler::HandleBanIPCommand(const char* args)
4870 return HandleBanHelper(BAN_IP,args);
4873 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4875 if(!args)
4876 return false;
4878 char* cnameOrIP = strtok ((char*)args, " ");
4879 if (!cnameOrIP)
4880 return false;
4882 std::string nameOrIP = cnameOrIP;
4884 char* duration = strtok (NULL," ");
4885 if(!duration || !atoi(duration))
4886 return false;
4888 char* reason = strtok (NULL,"");
4889 if(!reason)
4890 return false;
4892 switch(mode)
4894 case BAN_ACCOUNT:
4895 if(!AccountMgr::normilizeString(nameOrIP))
4897 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4898 SetSentErrorMessage(true);
4899 return false;
4901 break;
4902 case BAN_CHARACTER:
4903 if(!normalizePlayerName(nameOrIP))
4905 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4906 SetSentErrorMessage(true);
4907 return false;
4909 break;
4910 case BAN_IP:
4911 if(!IsIPAddress(nameOrIP.c_str()))
4912 return false;
4913 break;
4916 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4918 case BAN_SUCCESS:
4919 if(atoi(duration)>0)
4920 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4921 else
4922 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4923 break;
4924 case BAN_SYNTAX_ERROR:
4925 return false;
4926 case BAN_NOTFOUND:
4927 switch(mode)
4929 default:
4930 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4931 break;
4932 case BAN_CHARACTER:
4933 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4934 break;
4935 case BAN_IP:
4936 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4937 break;
4939 SetSentErrorMessage(true);
4940 return false;
4943 return true;
4946 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4948 return HandleUnBanHelper(BAN_ACCOUNT,args);
4951 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4953 return HandleUnBanHelper(BAN_CHARACTER,args);
4956 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4958 return HandleUnBanHelper(BAN_IP,args);
4961 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4963 if(!args)
4964 return false;
4966 char* cnameOrIP = strtok ((char*)args, " ");
4967 if(!cnameOrIP)
4968 return false;
4970 std::string nameOrIP = cnameOrIP;
4972 switch(mode)
4974 case BAN_ACCOUNT:
4975 if(!AccountMgr::normilizeString(nameOrIP))
4977 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4978 SetSentErrorMessage(true);
4979 return false;
4981 break;
4982 case BAN_CHARACTER:
4983 if(!normalizePlayerName(nameOrIP))
4985 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4986 SetSentErrorMessage(true);
4987 return false;
4989 break;
4990 case BAN_IP:
4991 if(!IsIPAddress(nameOrIP.c_str()))
4992 return false;
4993 break;
4996 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4997 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4998 else
4999 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5001 return true;
5004 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5006 if(!args)
5007 return false;
5009 char* cname = strtok((char*)args, "");
5010 if(!cname)
5011 return false;
5013 std::string account_name = cname;
5014 if(!AccountMgr::normilizeString(account_name))
5016 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5017 SetSentErrorMessage(true);
5018 return false;
5021 uint32 accountid = accmgr.GetId(account_name);
5022 if(!accountid)
5024 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5025 return true;
5028 return HandleBanInfoHelper(accountid,account_name.c_str());
5031 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5033 if(!args)
5034 return false;
5036 char* cname = strtok ((char*)args, "");
5037 if(!cname)
5038 return false;
5040 std::string name = cname;
5041 if(!normalizePlayerName(name))
5043 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5044 SetSentErrorMessage(true);
5045 return false;
5048 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5049 if(!accountid)
5051 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5052 SetSentErrorMessage(true);
5053 return false;
5056 std::string accountname;
5057 if(!accmgr.GetName(accountid,accountname))
5059 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5060 return true;
5063 return HandleBanInfoHelper(accountid,accountname.c_str());
5066 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5068 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
5069 if(!result)
5071 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5072 return true;
5075 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5078 Field* fields = result->Fetch();
5080 time_t unbandate = time_t(fields[3].GetUInt64());
5081 bool active = false;
5082 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5083 active = true;
5084 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5085 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5086 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5087 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5088 }while (result->NextRow());
5090 delete result;
5091 return true;
5094 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5096 if(!args)
5097 return false;
5099 char* cIP = strtok ((char*)args, "");
5100 if(!cIP)
5101 return false;
5103 if (!IsIPAddress(cIP))
5104 return false;
5106 std::string IP = cIP;
5108 loginDatabase.escape_string(IP);
5109 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
5110 if(!result)
5112 PSendSysMessage(LANG_BANINFO_NOIP);
5113 return true;
5116 Field *fields = result->Fetch();
5117 bool permanent = !fields[6].GetUInt64();
5118 PSendSysMessage(LANG_BANINFO_IPENTRY,
5119 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5120 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5121 delete result;
5122 return true;
5125 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5127 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5129 char* cFilter = strtok ((char*)args, " ");
5130 if(!cFilter)
5131 return false;
5133 std::string filter = cFilter;
5134 loginDatabase.escape_string(filter);
5135 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5136 if (!result)
5138 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5139 return true;
5142 return HandleBanListHelper(result);
5145 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5147 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5149 char* cFilter = strtok((char*)args, " ");
5150 std::string filter = cFilter ? cFilter : "";
5151 loginDatabase.escape_string(filter);
5153 QueryResult* result;
5155 if(filter.empty())
5157 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5158 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5160 else
5162 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5163 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5164 filter.c_str());
5167 if (!result)
5169 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5170 return true;
5173 return HandleBanListHelper(result);
5176 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5178 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5180 // Chat short output
5181 if(m_session)
5185 Field* fields = result->Fetch();
5186 uint32 accountid = fields[0].GetUInt32();
5188 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5189 if(banresult)
5191 Field* fields2 = banresult->Fetch();
5192 PSendSysMessage("%s",fields2[0].GetString());
5193 delete banresult;
5195 } while (result->NextRow());
5197 // Console wide output
5198 else
5200 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5201 SendSysMessage("===============================================================================");
5202 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5205 SendSysMessage("-------------------------------------------------------------------------------");
5206 Field *fields = result->Fetch();
5207 uint32 account_id = fields[0].GetUInt32 ();
5209 std::string account_name;
5211 // "account" case, name can be get in same query
5212 if(result->GetFieldCount() > 1)
5213 account_name = fields[1].GetCppString();
5214 // "character" case, name need extract from another DB
5215 else
5216 accmgr.GetName (account_id,account_name);
5218 // No SQL injection. id is uint32.
5219 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5220 if (banInfo)
5222 Field *fields2 = banInfo->Fetch();
5225 time_t t_ban = fields2[0].GetUInt64();
5226 tm* aTm_ban = localtime(&t_ban);
5228 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5230 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5231 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5232 fields2[2].GetString(),fields2[3].GetString());
5234 else
5236 time_t t_unban = fields2[1].GetUInt64();
5237 tm* aTm_unban = localtime(&t_unban);
5238 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5239 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5240 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5241 fields2[2].GetString(),fields2[3].GetString());
5243 }while ( banInfo->NextRow() );
5244 delete banInfo;
5246 }while( result->NextRow() );
5247 SendSysMessage("===============================================================================");
5250 delete result;
5251 return true;
5254 bool ChatHandler::HandleBanListIPCommand(const char* args)
5256 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5258 char* cFilter = strtok((char*)args, " ");
5259 std::string filter = cFilter ? cFilter : "";
5260 loginDatabase.escape_string(filter);
5262 QueryResult* result;
5264 if(filter.empty())
5266 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5267 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5268 " ORDER BY unbandate" );
5270 else
5272 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5273 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5274 " ORDER BY unbandate",filter.c_str() );
5277 if(!result)
5279 PSendSysMessage(LANG_BANLIST_NOIP);
5280 return true;
5283 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5284 // Chat short output
5285 if(m_session)
5289 Field* fields = result->Fetch();
5290 PSendSysMessage("%s",fields[0].GetString());
5291 } while (result->NextRow());
5293 // Console wide output
5294 else
5296 SendSysMessage(LANG_BANLIST_IPS);
5297 SendSysMessage("===============================================================================");
5298 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5301 SendSysMessage("-------------------------------------------------------------------------------");
5302 Field *fields = result->Fetch();
5303 time_t t_ban = fields[1].GetUInt64();
5304 tm* aTm_ban = localtime(&t_ban);
5305 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5307 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5308 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5309 fields[3].GetString(), fields[4].GetString());
5311 else
5313 time_t t_unban = fields[2].GetUInt64();
5314 tm* aTm_unban = localtime(&t_unban);
5315 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5316 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5317 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5318 fields[3].GetString(), fields[4].GetString());
5320 }while( result->NextRow() );
5321 SendSysMessage("===============================================================================");
5324 delete result;
5325 return true;
5328 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5330 Player* pl = m_session->GetPlayer();
5332 // accept only explicitly selected target (not implicitly self targeting case)
5333 Unit* target = getSelectedUnit();
5334 if(pl->GetSelection() && target)
5336 if(target->GetTypeId()!=TYPEID_UNIT)
5338 SendSysMessage(LANG_SELECT_CREATURE);
5339 SetSentErrorMessage(true);
5340 return false;
5343 if(target->isDead())
5344 ((Creature*)target)->Respawn();
5345 return true;
5348 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5349 Cell cell(p);
5350 cell.data.Part.reserved = ALL_DISTRICT;
5351 cell.SetNoCreate();
5353 MaNGOS::RespawnDo u_do;
5354 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5356 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5357 CellLock<GridReadGuard> cell_lock(cell, p);
5358 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5360 return true;
5363 bool ChatHandler::HandleFlyModeCommand(const char* args)
5365 if(!args)
5366 return false;
5368 Unit *unit = getSelectedUnit();
5369 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5370 unit = m_session->GetPlayer();
5372 WorldPacket data(12);
5373 if (strncmp(args, "on", 3) == 0)
5374 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5375 else if (strncmp(args, "off", 4) == 0)
5376 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5377 else
5379 SendSysMessage(LANG_USE_BOL);
5380 return false;
5382 data.append(unit->GetPackGUID());
5383 data << uint32(0); // unknown
5384 unit->SendMessageToSet(&data, true);
5385 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5386 return true;
5389 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5391 if(!args)
5392 return false;
5394 char * file = strtok((char*)args, " ");
5395 if(!file)
5396 return false;
5398 char * account = strtok(NULL, " ");
5399 if(!account)
5400 return false;
5402 std::string account_name = account;
5403 if(!AccountMgr::normilizeString(account_name))
5405 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5406 SetSentErrorMessage(true);
5407 return false;
5410 uint32 account_id = accmgr.GetId(account_name);
5411 if(!account_id)
5413 account_id = atoi(account); // use original string
5414 if(!account_id)
5416 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5417 SetSentErrorMessage(true);
5418 return false;
5422 if(!accmgr.GetName(account_id,account_name))
5424 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5425 SetSentErrorMessage(true);
5426 return false;
5429 char* guid_str = NULL;
5430 char* name_str = strtok(NULL, " ");
5432 std::string name;
5433 if(name_str)
5435 name = name_str;
5436 // normalize the name if specified and check if it exists
5437 if(!normalizePlayerName(name))
5439 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5440 SetSentErrorMessage(true);
5441 return false;
5444 if(!ObjectMgr::IsValidName(name,true))
5446 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5447 SetSentErrorMessage(true);
5448 return false;
5451 guid_str = strtok(NULL, " ");
5454 uint32 guid = 0;
5456 if(guid_str)
5458 guid = atoi(guid_str);
5459 if(!guid)
5461 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5462 SetSentErrorMessage(true);
5463 return false;
5466 if(objmgr.GetPlayerAccountIdByGUID(guid))
5468 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5469 SetSentErrorMessage(true);
5470 return false;
5474 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5476 case DUMP_SUCCESS:
5477 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5478 break;
5479 case DUMP_FILE_OPEN_ERROR:
5480 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5481 SetSentErrorMessage(true);
5482 return false;
5483 case DUMP_FILE_BROKEN:
5484 PSendSysMessage(LANG_DUMP_BROKEN,file);
5485 SetSentErrorMessage(true);
5486 return false;
5487 case DUMP_TOO_MANY_CHARS:
5488 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5489 SetSentErrorMessage(true);
5490 return false;
5491 default:
5492 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5493 SetSentErrorMessage(true);
5494 return false;
5497 return true;
5500 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
5502 if(!args)
5503 return false;
5505 uint32 newEntryNum = atoi(args);
5506 if(!newEntryNum)
5507 return false;
5509 Unit* unit = getSelectedUnit();
5510 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5512 SendSysMessage(LANG_SELECT_CREATURE);
5513 SetSentErrorMessage(true);
5514 return false;
5516 Creature* creature = (Creature*)unit;
5517 if(creature->UpdateEntry(newEntryNum))
5518 SendSysMessage(LANG_DONE);
5519 else
5520 SendSysMessage(LANG_ERROR);
5521 return true;
5524 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5526 if(!args)
5527 return false;
5529 char* file = strtok((char*)args, " ");
5530 char* p2 = strtok(NULL, " ");
5532 if(!file || !p2)
5533 return false;
5535 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5536 if(!guid)
5537 guid = atoi(p2);
5539 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5541 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5542 SetSentErrorMessage(true);
5543 return false;
5546 switch(PlayerDumpWriter().WriteDump(file, guid))
5548 case DUMP_SUCCESS:
5549 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5550 break;
5551 case DUMP_FILE_OPEN_ERROR:
5552 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5553 SetSentErrorMessage(true);
5554 return false;
5555 default:
5556 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5557 SetSentErrorMessage(true);
5558 return false;
5561 return true;
5564 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5566 Unit* unit = getSelectedUnit();
5567 if(!unit)
5569 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5570 SetSentErrorMessage(true);
5571 return false;
5574 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5576 MotionMaster* mm = unit->GetMotionMaster();
5577 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5579 switch((*itr)->GetMovementGeneratorType())
5581 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5582 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5583 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5584 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5585 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5586 case TARGETED_MOTION_TYPE:
5588 if(unit->GetTypeId()==TYPEID_PLAYER)
5590 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5591 Unit* target = mgen->GetTarget();
5592 if(target)
5593 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5594 else
5595 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5597 else
5599 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5600 Unit* target = mgen->GetTarget();
5601 if(target)
5602 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5603 else
5604 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5606 break;
5608 case HOME_MOTION_TYPE:
5609 if(unit->GetTypeId()==TYPEID_UNIT)
5611 float x,y,z;
5612 (*itr)->GetDestination(x,y,z);
5613 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5615 else
5616 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5617 break;
5618 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5619 case POINT_MOTION_TYPE:
5621 float x,y,z;
5622 (*itr)->GetDestination(x,y,z);
5623 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5624 break;
5626 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5627 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5628 default:
5629 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5630 break;
5633 return true;
5636 bool ChatHandler::HandlePLimitCommand(const char *args)
5638 if(*args)
5640 char* param = strtok((char*)args, " ");
5641 if(!param)
5642 return false;
5644 int l = strlen(param);
5646 if( strncmp(param,"player",l) == 0 )
5647 sWorld.SetPlayerLimit(-SEC_PLAYER);
5648 else if(strncmp(param,"moderator",l) == 0 )
5649 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5650 else if(strncmp(param,"gamemaster",l) == 0 )
5651 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5652 else if(strncmp(param,"administrator",l) == 0 )
5653 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5654 else if(strncmp(param,"reset",l) == 0 )
5655 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5656 else
5658 int val = atoi(param);
5659 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5661 sWorld.SetPlayerLimit(val);
5664 // kick all low security level players
5665 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5666 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5669 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5670 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5671 char const* secName = "";
5672 switch(allowedAccountType)
5674 case SEC_PLAYER: secName = "Player"; break;
5675 case SEC_MODERATOR: secName = "Moderator"; break;
5676 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5677 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5678 default: secName = "<unknown>"; break;
5681 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5683 return true;
5686 bool ChatHandler::HandleCastCommand(const char* args)
5688 if(!*args)
5689 return false;
5691 Unit* target = getSelectedUnit();
5693 if(!target)
5695 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5696 SetSentErrorMessage(true);
5697 return false;
5700 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5701 uint32 spell = extractSpellIdFromLink((char*)args);
5702 if(!spell)
5703 return false;
5705 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5706 if(!spellInfo)
5707 return false;
5709 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5711 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5712 SetSentErrorMessage(true);
5713 return false;
5716 char* trig_str = strtok(NULL, " ");
5717 if(trig_str)
5719 int l = strlen(trig_str);
5720 if(strncmp(trig_str,"triggered",l) != 0 )
5721 return false;
5724 bool triggered = (trig_str != NULL);
5726 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5728 return true;
5731 bool ChatHandler::HandleCastBackCommand(const char* args)
5733 Creature* caster = getSelectedCreature();
5735 if(!caster)
5737 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5738 SetSentErrorMessage(true);
5739 return false;
5742 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5743 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5744 uint32 spell = extractSpellIdFromLink((char*)args);
5745 if(!spell || !sSpellStore.LookupEntry(spell))
5746 return false;
5748 char* trig_str = strtok(NULL, " ");
5749 if(trig_str)
5751 int l = strlen(trig_str);
5752 if(strncmp(trig_str,"triggered",l) != 0 )
5753 return false;
5756 bool triggered = (trig_str != NULL);
5758 // update orientation at server
5759 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5761 // and client
5762 WorldPacket data;
5763 caster->BuildHeartBeatMsg(&data);
5764 caster->SendMessageToSet(&data,true);
5766 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5768 return true;
5771 bool ChatHandler::HandleCastDistCommand(const char* args)
5773 if(!*args)
5774 return false;
5776 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5777 uint32 spell = extractSpellIdFromLink((char*)args);
5778 if(!spell)
5779 return false;
5781 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5782 if(!spellInfo)
5783 return false;
5785 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5787 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5788 SetSentErrorMessage(true);
5789 return false;
5792 char *distStr = strtok(NULL, " ");
5794 float dist = 0;
5796 if(distStr)
5797 sscanf(distStr, "%f", &dist);
5799 char* trig_str = strtok(NULL, " ");
5800 if(trig_str)
5802 int l = strlen(trig_str);
5803 if(strncmp(trig_str,"triggered",l) != 0 )
5804 return false;
5807 bool triggered = (trig_str != NULL);
5809 float x,y,z;
5810 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5812 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5813 return true;
5816 bool ChatHandler::HandleCastTargetCommand(const char* args)
5818 Creature* caster = getSelectedCreature();
5820 if(!caster)
5822 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5823 SetSentErrorMessage(true);
5824 return false;
5827 if(!caster->getVictim())
5829 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5830 SetSentErrorMessage(true);
5831 return false;
5834 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5835 uint32 spell = extractSpellIdFromLink((char*)args);
5836 if(!spell || !sSpellStore.LookupEntry(spell))
5837 return false;
5839 char* trig_str = strtok(NULL, " ");
5840 if(trig_str)
5842 int l = strlen(trig_str);
5843 if(strncmp(trig_str,"triggered",l) != 0 )
5844 return false;
5847 bool triggered = (trig_str != NULL);
5849 // update orientation at server
5850 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5852 // and client
5853 WorldPacket data;
5854 caster->BuildHeartBeatMsg(&data);
5855 caster->SendMessageToSet(&data,true);
5857 caster->CastSpell(caster->getVictim(),spell,triggered);
5859 return true;
5863 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5864 Without this function 3rd party scripting library will get linking errors (unresolved external)
5865 when attempting to use the PointMovementGenerator
5867 bool ChatHandler::HandleComeToMeCommand(const char *args)
5869 Creature* caster = getSelectedCreature();
5871 if(!caster)
5873 SendSysMessage(LANG_SELECT_CREATURE);
5874 SetSentErrorMessage(true);
5875 return false;
5878 char* newFlagStr = strtok((char*)args, " ");
5880 if(!newFlagStr)
5881 return false;
5883 uint32 newFlags = atoi(newFlagStr);
5885 caster->SetUnitMovementFlags(newFlags);
5887 Player* pl = m_session->GetPlayer();
5889 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5890 return true;
5893 bool ChatHandler::HandleCastSelfCommand(const char* args)
5895 if(!*args)
5896 return false;
5898 Unit* target = getSelectedUnit();
5900 if(!target)
5902 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5903 SetSentErrorMessage(true);
5904 return false;
5907 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5908 uint32 spell = extractSpellIdFromLink((char*)args);
5909 if(!spell)
5910 return false;
5912 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5913 if(!spellInfo)
5914 return false;
5916 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5918 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5919 SetSentErrorMessage(true);
5920 return false;
5923 target->CastSpell(target,spell,false);
5925 return true;
5928 std::string GetTimeString(uint32 time)
5930 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5931 std::ostringstream ss;
5932 if(days) ss << days << "d ";
5933 if(hours) ss << hours << "h ";
5934 ss << minute << "m";
5935 return ss.str();
5938 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5940 Player* player = getSelectedPlayer();
5941 if (!player) player = m_session->GetPlayer();
5942 uint32 counter = 0;
5943 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5945 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5946 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5948 InstanceSave *save = itr->second.save;
5949 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5950 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5951 counter++;
5954 PSendSysMessage("player binds: %d", counter);
5955 counter = 0;
5956 Group *group = player->GetGroup();
5957 if(group)
5959 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5961 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5962 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5964 InstanceSave *save = itr->second.save;
5965 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5966 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5967 counter++;
5971 PSendSysMessage("group binds: %d", counter);
5973 return true;
5976 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5978 if(!*args)
5979 return false;
5981 std::string cmd = args;
5982 if(cmd == "all")
5984 Player* player = getSelectedPlayer();
5985 if (!player) player = m_session->GetPlayer();
5986 uint32 counter = 0;
5987 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5989 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5990 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5992 if(itr->first != player->GetMapId())
5994 InstanceSave *save = itr->second.save;
5995 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5996 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5997 player->UnbindInstance(itr, i);
5998 counter++;
6000 else
6001 ++itr;
6004 PSendSysMessage("instances unbound: %d", counter);
6006 return true;
6009 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6011 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6012 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6013 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6014 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6015 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6016 return true;
6019 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6021 Player* pl = m_session->GetPlayer();
6023 Map* map = pl->GetMap();
6024 if (!map->IsDungeon())
6026 PSendSysMessage("Map is not a dungeon.");
6027 SetSentErrorMessage(true);
6028 return false;
6031 if (!((InstanceMap*)map)->GetInstanceData())
6033 PSendSysMessage("Map has no instance data.");
6034 SetSentErrorMessage(true);
6035 return false;
6038 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6039 return true;
6042 /// Display the list of GMs
6043 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6045 ///- Get the accounts with GM Level >0
6046 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6047 if(result)
6049 SendSysMessage(LANG_GMLIST);
6050 SendSysMessage("========================");
6051 SendSysMessage(LANG_GMLIST_HEADER);
6052 SendSysMessage("========================");
6054 ///- Circle through them. Display username and GM level
6057 Field *fields = result->Fetch();
6058 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6059 }while( result->NextRow() );
6061 PSendSysMessage("========================");
6062 delete result;
6064 else
6065 PSendSysMessage(LANG_GMLIST_EMPTY);
6066 return true;
6069 /// Define the 'Message of the day' for the realm
6070 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6072 sWorld.SetMotd(args);
6073 PSendSysMessage(LANG_MOTD_NEW, args);
6074 return true;
6077 /// Set/Unset the expansion level for an account
6078 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6080 ///- Get the command line arguments
6081 char *szAcc = strtok((char*)args," ");
6082 char *szExp = strtok(NULL," ");
6084 if(!szAcc)
6085 return false;
6087 std::string account_name;
6088 uint32 account_id;
6090 if(!szExp)
6092 Player* player = getSelectedPlayer();
6093 if(!player)
6094 return false;
6096 account_id = player->GetSession()->GetAccountId();
6097 accmgr.GetName(account_id,account_name);
6098 szExp = szAcc;
6100 else
6102 ///- Convert Account name to Upper Format
6103 account_name = szAcc;
6104 if(!AccountMgr::normilizeString(account_name))
6106 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6107 SetSentErrorMessage(true);
6108 return false;
6111 account_id = accmgr.GetId(account_name);
6112 if(!account_id)
6114 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6115 SetSentErrorMessage(true);
6116 return false;
6120 int lev=atoi(szExp); //get int anyway (0 if error)
6121 if(lev < 0)
6122 return false;
6124 // No SQL injection
6125 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6126 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6127 return true;
6130 /// Send a message to a player in game
6131 bool ChatHandler::HandleSendMessageCommand(const char* args)
6133 ///- Get the command line arguments
6134 char* name_str = strtok((char*)args, " ");
6135 char* msg_str = strtok(NULL, "");
6137 if(!name_str || !msg_str)
6138 return false;
6140 std::string name = name_str;
6142 if(!normalizePlayerName(name))
6143 return false;
6145 ///- Find the player and check that he is not logging out.
6146 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6147 if(!rPlayer)
6149 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6150 SetSentErrorMessage(true);
6151 return false;
6154 if(rPlayer->GetSession()->isLogingOut())
6156 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6157 SetSentErrorMessage(true);
6158 return false;
6161 ///- Send the message
6162 //Use SendAreaTriggerMessage for fastest delivery.
6163 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6164 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6166 //Confirmation message
6167 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6168 return true;
6171 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6173 if(!*args)
6174 return false;
6176 Player *player = getSelectedPlayer();
6178 if(!player)
6180 PSendSysMessage(LANG_NO_PLAYER);
6181 SetSentErrorMessage(true);
6182 return false;
6185 char const* gender_str = (char*)args;
6186 int gender_len = strlen(gender_str);
6188 uint32 displayId = player->GetNativeDisplayId();
6189 char const* gender_full = NULL;
6190 uint32 new_displayId = displayId;
6191 Gender gender;
6193 if(!strncmp(gender_str,"male",gender_len)) // MALE
6195 if(player->getGender() == GENDER_MALE)
6196 return true;
6198 gender_full = "male";
6199 new_displayId = player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1;
6200 gender = GENDER_MALE;
6202 else if (!strncmp(gender_str,"female",gender_len)) // FEMALE
6204 if(player->getGender() == GENDER_FEMALE)
6205 return true;
6207 gender_full = "female";
6208 new_displayId = player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1;
6209 gender = GENDER_FEMALE;
6211 else
6213 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6214 SetSentErrorMessage(true);
6215 return false;
6218 // Set gender
6219 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6221 // Change display ID
6222 player->SetDisplayId(new_displayId);
6223 player->SetNativeDisplayId(new_displayId);
6225 PSendSysMessage(LANG_YOU_CHANGE_GENDER, player->GetName(),gender_full);
6226 if (needReportToTarget(player))
6227 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full,GetName());
6228 return true;