[6813] Allow have team dependent graveyards at entrance map for instances.
[getmangos.git] / src / game / Level3.cpp
blob6d12b8ba7f834d96b759b20287b49b1a56eb1d6c
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(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3531 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3532 else
3533 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3535 return true;
3538 bool ChatHandler::HandleNearGraveCommand(const char* args)
3540 uint32 g_team;
3542 size_t argslen = strlen(args);
3544 if(!*args)
3545 g_team = 0;
3546 else if (strncmp((char*)args,"horde",argslen)==0)
3547 g_team = HORDE;
3548 else if (strncmp((char*)args,"alliance",argslen)==0)
3549 g_team = ALLIANCE;
3550 else
3551 return false;
3553 Player* player = m_session->GetPlayer();
3555 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3556 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3558 if(graveyard)
3560 uint32 g_id = graveyard->ID;
3562 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3563 if (!data)
3565 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3566 SetSentErrorMessage(true);
3567 return false;
3570 g_team = data->team;
3572 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3574 if(g_team == 0)
3575 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3576 else if(g_team == HORDE)
3577 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3578 else if(g_team == ALLIANCE)
3579 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3581 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3583 else
3585 std::string team_name;
3587 if(g_team == 0)
3588 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3589 else if(g_team == HORDE)
3590 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3591 else if(g_team == ALLIANCE)
3592 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3594 if(g_team == ~uint32(0))
3595 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3596 else
3597 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3600 return true;
3603 //play npc emote
3604 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3606 uint32 emote = atoi((char*)args);
3608 Creature* target = getSelectedCreature();
3609 if(!target)
3611 SendSysMessage(LANG_SELECT_CREATURE);
3612 SetSentErrorMessage(true);
3613 return false;
3616 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3618 return true;
3621 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3623 Creature* target = getSelectedCreature();
3625 if(!target)
3627 SendSysMessage(LANG_SELECT_CREATURE);
3628 SetSentErrorMessage(true);
3629 return false;
3632 uint32 faction = target->getFaction();
3633 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3634 uint32 displayid = target->GetDisplayId();
3635 uint32 nativeid = target->GetNativeDisplayId();
3636 uint32 Entry = target->GetEntry();
3637 CreatureInfo const* cInfo = target->GetCreatureInfo();
3639 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3640 if(curRespawnDelay < 0)
3641 curRespawnDelay = 0;
3642 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3643 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3645 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3646 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3647 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3648 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3649 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3650 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3651 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3652 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3654 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3656 SendSysMessage(LANG_NPCINFO_VENDOR);
3658 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3660 SendSysMessage(LANG_NPCINFO_TRAINER);
3663 return true;
3666 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3668 if (!*args)
3669 return false;
3671 int flag = atoi((char*)args);
3673 Player *chr = getSelectedPlayer();
3674 if (chr == NULL)
3676 SendSysMessage(LANG_NO_CHAR_SELECTED);
3677 SetSentErrorMessage(true);
3678 return false;
3681 if (flag != 0)
3683 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3684 if (needReportToTarget(chr))
3685 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetName());
3687 else
3689 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3690 if (needReportToTarget(chr))
3691 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetName());
3694 for (uint8 i=0; i<128; i++)
3696 if (flag != 0)
3698 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3700 else
3702 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3706 return true;
3709 bool ChatHandler::HandleHoverCommand(const char* args)
3711 char* px = strtok((char*)args, " ");
3712 uint32 flag;
3713 if (!px)
3714 flag = 1;
3715 else
3716 flag = atoi(px);
3718 m_session->GetPlayer()->SetHover(flag);
3720 if (flag)
3721 SendSysMessage(LANG_HOVER_ENABLED);
3722 else
3723 SendSysMessage(LANG_HOVER_DISABLED);
3725 return true;
3728 bool ChatHandler::HandleLevelUpCommand(const char* args)
3730 char* px = strtok((char*)args, " ");
3731 char* py = strtok((char*)NULL, " ");
3733 // command format parsing
3734 char* pname = (char*)NULL;
3735 int addlevel = 1;
3737 if(px && py) // .levelup name level
3739 addlevel = atoi(py);
3740 pname = px;
3742 else if(px && !py) // .levelup name OR .levelup level
3744 if(isalpha(px[0])) // .levelup name
3745 pname = px;
3746 else // .levelup level
3747 addlevel = atoi(px);
3749 // else .levelup - nothing do for preparing
3751 // player
3752 Player *chr = NULL;
3753 uint64 chr_guid = 0;
3755 std::string name;
3757 if(pname) // player by name
3759 name = pname;
3760 if(!normalizePlayerName(name))
3762 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3763 SetSentErrorMessage(true);
3764 return false;
3767 chr = objmgr.GetPlayer(name.c_str());
3768 if(!chr) // not in game
3770 chr_guid = objmgr.GetPlayerGUIDByName(name);
3771 if (chr_guid == 0)
3773 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3774 SetSentErrorMessage(true);
3775 return false;
3779 else // player by selection
3781 chr = getSelectedPlayer();
3783 if (chr == NULL)
3785 SendSysMessage(LANG_NO_CHAR_SELECTED);
3786 SetSentErrorMessage(true);
3787 return false;
3790 name = chr->GetName();
3793 assert(chr || chr_guid);
3795 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3796 int32 newlevel = oldlevel + addlevel;
3797 if(newlevel < 1)
3798 newlevel = 1;
3799 if(newlevel > 255) // hardcoded maximum level
3800 newlevel = 255;
3802 if(chr)
3804 chr->GiveLevel(newlevel);
3805 chr->InitTalentForLevel();
3806 chr->SetUInt32Value(PLAYER_XP,0);
3808 if(oldlevel == newlevel)
3809 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3810 else
3811 if(oldlevel < newlevel)
3812 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3813 else
3814 if(oldlevel > newlevel)
3815 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3817 else
3819 // update level and XP at level, all other will be updated at loading
3820 Tokens values;
3821 Player::LoadValuesArrayFromDB(values,chr_guid);
3822 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3823 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3824 Player::SaveValuesArrayInDB(values,chr_guid);
3827 if(m_session->GetPlayer() != chr) // including chr==NULL
3828 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3829 return true;
3832 bool ChatHandler::HandleShowAreaCommand(const char* args)
3834 if (!*args)
3835 return false;
3837 int area = atoi((char*)args);
3839 Player *chr = getSelectedPlayer();
3840 if (chr == NULL)
3842 SendSysMessage(LANG_NO_CHAR_SELECTED);
3843 SetSentErrorMessage(true);
3844 return false;
3847 int offset = area / 32;
3848 uint32 val = (uint32)(1 << (area % 32));
3850 if(offset >= 128)
3852 SendSysMessage(LANG_BAD_VALUE);
3853 SetSentErrorMessage(true);
3854 return false;
3857 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3858 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3860 SendSysMessage(LANG_EXPLORE_AREA);
3861 return true;
3864 bool ChatHandler::HandleHideAreaCommand(const char* args)
3866 if (!*args)
3867 return false;
3869 int area = atoi((char*)args);
3871 Player *chr = getSelectedPlayer();
3872 if (chr == NULL)
3874 SendSysMessage(LANG_NO_CHAR_SELECTED);
3875 SetSentErrorMessage(true);
3876 return false;
3879 int offset = area / 32;
3880 uint32 val = (uint32)(1 << (area % 32));
3882 if(offset >= 128)
3884 SendSysMessage(LANG_BAD_VALUE);
3885 SetSentErrorMessage(true);
3886 return false;
3889 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3890 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3892 SendSysMessage(LANG_UNEXPLORE_AREA);
3893 return true;
3896 bool ChatHandler::HandleUpdate(const char* args)
3898 if(!*args)
3899 return false;
3901 uint32 updateIndex;
3902 uint32 value;
3904 char* pUpdateIndex = strtok((char*)args, " ");
3906 Unit* chr = getSelectedUnit();
3907 if (chr == NULL)
3909 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3910 SetSentErrorMessage(true);
3911 return false;
3914 if(!pUpdateIndex)
3916 return true;
3918 updateIndex = atoi(pUpdateIndex);
3919 //check updateIndex
3920 if(chr->GetTypeId() == TYPEID_PLAYER)
3922 if (updateIndex>=PLAYER_END) return true;
3924 else
3926 if (updateIndex>=UNIT_END) return true;
3929 char* pvalue = strtok(NULL, " ");
3930 if (!pvalue)
3932 value=chr->GetUInt32Value(updateIndex);
3934 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3935 return true;
3938 value=atoi(pvalue);
3940 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3942 chr->SetUInt32Value(updateIndex,value);
3944 return true;
3947 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3949 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3951 return true;
3954 bool ChatHandler::HandleChangeWeather(const char* args)
3956 if(!*args)
3957 return false;
3959 //Weather is OFF
3960 if (!sWorld.getConfig(CONFIG_WEATHER))
3962 SendSysMessage(LANG_WEATHER_DISABLED);
3963 SetSentErrorMessage(true);
3964 return false;
3967 //*Change the weather of a cell
3968 char* px = strtok((char*)args, " ");
3969 char* py = strtok(NULL, " ");
3971 if (!px || !py)
3972 return false;
3974 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3975 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3977 Player *player = m_session->GetPlayer();
3978 uint32 zoneid = player->GetZoneId();
3980 Weather* wth = sWorld.FindWeather(zoneid);
3982 if(!wth)
3983 wth = sWorld.AddWeather(zoneid);
3984 if(!wth)
3986 SendSysMessage(LANG_NO_WEATHER);
3987 SetSentErrorMessage(true);
3988 return false;
3991 wth->SetWeather(WeatherType(type), grade);
3993 return true;
3996 bool ChatHandler::HandleSetValue(const char* args)
3998 if(!*args)
3999 return false;
4001 char* px = strtok((char*)args, " ");
4002 char* py = strtok(NULL, " ");
4003 char* pz = strtok(NULL, " ");
4005 if (!px || !py)
4006 return false;
4008 Unit* target = getSelectedUnit();
4009 if(!target)
4011 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4012 SetSentErrorMessage(true);
4013 return false;
4016 uint64 guid = target->GetGUID();
4018 uint32 Opcode = (uint32)atoi(px);
4019 if(Opcode >= target->GetValuesCount())
4021 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4022 return false;
4024 uint32 iValue;
4025 float fValue;
4026 bool isint32 = true;
4027 if(pz)
4028 isint32 = (bool)atoi(pz);
4029 if(isint32)
4031 iValue = (uint32)atoi(py);
4032 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4033 target->SetUInt32Value( Opcode , iValue );
4034 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4036 else
4038 fValue = (float)atof(py);
4039 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4040 target->SetFloatValue( Opcode , fValue );
4041 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4044 return true;
4047 bool ChatHandler::HandleGetValue(const char* args)
4049 if(!*args)
4050 return false;
4052 char* px = strtok((char*)args, " ");
4053 char* pz = strtok(NULL, " ");
4055 if (!px)
4056 return false;
4058 Unit* target = getSelectedUnit();
4059 if(!target)
4061 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4062 SetSentErrorMessage(true);
4063 return false;
4066 uint64 guid = target->GetGUID();
4068 uint32 Opcode = (uint32)atoi(px);
4069 if(Opcode >= target->GetValuesCount())
4071 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4072 return false;
4074 uint32 iValue;
4075 float fValue;
4076 bool isint32 = true;
4077 if(pz)
4078 isint32 = (bool)atoi(pz);
4080 if(isint32)
4082 iValue = target->GetUInt32Value( Opcode );
4083 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4084 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4086 else
4088 fValue = target->GetFloatValue( Opcode );
4089 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4090 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4093 return true;
4096 bool ChatHandler::HandleSet32Bit(const char* args)
4098 if(!*args)
4099 return false;
4101 char* px = strtok((char*)args, " ");
4102 char* py = strtok(NULL, " ");
4104 if (!px || !py)
4105 return false;
4107 uint32 Opcode = (uint32)atoi(px);
4108 uint32 Value = (uint32)atoi(py);
4109 if (Value > 32) //uint32 = 32 bits
4110 return false;
4112 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4114 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4116 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4117 return true;
4120 bool ChatHandler::HandleMod32Value(const char* args)
4122 if(!*args)
4123 return false;
4125 char* px = strtok((char*)args, " ");
4126 char* py = strtok(NULL, " ");
4128 if (!px || !py)
4129 return false;
4131 uint32 Opcode = (uint32)atoi(px);
4132 int Value = atoi(py);
4134 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4136 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4137 return false;
4140 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4142 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4144 CurrentValue += Value;
4145 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4147 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4149 return true;
4152 bool ChatHandler::HandleAddTeleCommand(const char * args)
4154 if(!*args)
4155 return false;
4157 Player *player=m_session->GetPlayer();
4158 if (!player)
4159 return false;
4161 std::string name = args;
4163 if(objmgr.GetGameTele(name))
4165 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4166 SetSentErrorMessage(true);
4167 return false;
4170 GameTele tele;
4171 tele.position_x = player->GetPositionX();
4172 tele.position_y = player->GetPositionY();
4173 tele.position_z = player->GetPositionZ();
4174 tele.orientation = player->GetOrientation();
4175 tele.mapId = player->GetMapId();
4176 tele.name = name;
4178 if(objmgr.AddGameTele(tele))
4180 SendSysMessage(LANG_COMMAND_TP_ADDED);
4182 else
4184 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4185 SetSentErrorMessage(true);
4186 return false;
4189 return true;
4192 bool ChatHandler::HandleDelTeleCommand(const char * args)
4194 if(!*args)
4195 return false;
4197 std::string name = args;
4199 if(!objmgr.DeleteGameTele(name))
4201 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4202 SetSentErrorMessage(true);
4203 return false;
4206 SendSysMessage(LANG_COMMAND_TP_DELETED);
4207 return true;
4210 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4212 Unit *unit = getSelectedUnit();
4213 if(!unit)
4215 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4216 SetSentErrorMessage(true);
4217 return false;
4220 char const* talentStr = GetMangosString(LANG_TALENT);
4221 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4223 Unit::AuraMap const& uAuras = unit->GetAuras();
4224 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4225 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4227 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4228 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4229 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4230 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4231 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4232 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4234 for (int i = 0; i < TOTAL_AURAS; i++)
4236 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4237 if (uAuraList.empty()) continue;
4238 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4239 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4241 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4242 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4243 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4244 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4247 return true;
4250 bool ChatHandler::HandleResetHonorCommand (const char * args)
4252 char* pName = strtok((char*)args, "");
4253 Player *player = NULL;
4254 if (pName)
4256 std::string name = pName;
4257 if(!normalizePlayerName(name))
4259 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4260 SetSentErrorMessage(true);
4261 return false;
4264 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4265 player = objmgr.GetPlayer(guid);
4267 else
4268 player = getSelectedPlayer();
4270 if(!player)
4272 SendSysMessage(LANG_NO_CHAR_SELECTED);
4273 return true;
4276 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4277 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4278 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4279 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4280 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4282 return true;
4285 static bool HandleResetStatsOrLevelHelper(Player* player)
4287 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4288 if(!info) return false;
4290 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4291 if(!cEntry)
4293 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4294 return false;
4297 uint8 powertype = cEntry->powerType;
4299 uint32 unitfield;
4300 if(powertype == POWER_RAGE)
4301 unitfield = 0x1100EE00;
4302 else if(powertype == POWER_ENERGY)
4303 unitfield = 0x00000000;
4304 else if(powertype == POWER_MANA)
4305 unitfield = 0x0000EE00;
4306 else
4308 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4309 return false;
4312 // reset m_form if no aura
4313 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4314 player->m_form = FORM_NONE;
4316 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4317 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4319 player->setFactionForRace(player->getRace());
4321 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4323 // reset only if player not in some form;
4324 if(player->m_form==FORM_NONE)
4326 switch(player->getGender())
4328 case GENDER_FEMALE:
4329 player->SetDisplayId(info->displayId_f);
4330 player->SetNativeDisplayId(info->displayId_f);
4331 break;
4332 case GENDER_MALE:
4333 player->SetDisplayId(info->displayId_m);
4334 player->SetNativeDisplayId(info->displayId_m);
4335 break;
4336 default:
4337 break;
4341 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4342 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4343 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4344 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4346 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4348 //-1 is default value
4349 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4351 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4352 return true;
4355 bool ChatHandler::HandleResetLevelCommand(const char * args)
4357 char* pName = strtok((char*)args, "");
4358 Player *player = NULL;
4359 if (pName)
4361 std::string name = pName;
4362 if(!normalizePlayerName(name))
4364 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4365 SetSentErrorMessage(true);
4366 return false;
4369 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4370 player = objmgr.GetPlayer(guid);
4372 else
4373 player = getSelectedPlayer();
4375 if(!player)
4377 SendSysMessage(LANG_NO_CHAR_SELECTED);
4378 SetSentErrorMessage(true);
4379 return false;
4382 if(!HandleResetStatsOrLevelHelper(player))
4383 return false;
4385 player->SetLevel(1);
4386 player->InitStatsForLevel(true);
4387 player->InitTaxiNodesForLevel();
4388 player->InitTalentForLevel();
4389 player->SetUInt32Value(PLAYER_XP,0);
4391 // reset level to summoned pet
4392 Pet* pet = player->GetPet();
4393 if(pet && pet->getPetType()==SUMMON_PET)
4394 pet->InitStatsForLevel(1);
4396 return true;
4399 bool ChatHandler::HandleResetStatsCommand(const char * args)
4401 char* pName = strtok((char*)args, "");
4402 Player *player = NULL;
4403 if (pName)
4405 std::string name = pName;
4406 if(!normalizePlayerName(name))
4408 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4409 SetSentErrorMessage(true);
4410 return false;
4413 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4414 player = objmgr.GetPlayer(guid);
4416 else
4417 player = getSelectedPlayer();
4419 if(!player)
4421 SendSysMessage(LANG_NO_CHAR_SELECTED);
4422 SetSentErrorMessage(true);
4423 return false;
4426 if(!HandleResetStatsOrLevelHelper(player))
4427 return false;
4429 player->InitStatsForLevel(true);
4430 player->InitTaxiNodesForLevel();
4431 player->InitTalentForLevel();
4433 return true;
4436 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4438 char* pName = strtok((char*)args, "");
4439 Player *player = NULL;
4440 uint64 playerGUID = 0;
4441 if (pName)
4443 std::string name = pName;
4445 if(!normalizePlayerName(name))
4447 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4448 SetSentErrorMessage(true);
4449 return false;
4452 player = objmgr.GetPlayer(name.c_str());
4453 if(!player)
4454 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4456 else
4457 player = getSelectedPlayer();
4459 if(!player && !playerGUID)
4461 SendSysMessage(LANG_NO_CHAR_SELECTED);
4462 SetSentErrorMessage(true);
4463 return false;
4466 if(player)
4468 player->resetSpells();
4470 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4472 if(m_session->GetPlayer()!=player)
4473 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4475 else
4477 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4478 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4481 return true;
4484 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4486 char* pName = strtok((char*)args, "");
4487 Player *player = NULL;
4488 uint64 playerGUID = 0;
4489 if (pName)
4491 std::string name = pName;
4492 if(!normalizePlayerName(name))
4494 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4495 SetSentErrorMessage(true);
4496 return false;
4499 player = objmgr.GetPlayer(name.c_str());
4500 if(!player)
4501 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4503 else
4504 player = getSelectedPlayer();
4506 if(!player && !playerGUID)
4508 SendSysMessage(LANG_NO_CHAR_SELECTED);
4509 SetSentErrorMessage(true);
4510 return false;
4513 if(player)
4515 player->resetTalents(true);
4517 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4519 if(m_session->GetPlayer()!=player)
4520 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4522 else
4524 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4525 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4528 return true;
4531 bool ChatHandler::HandleResetAllCommand(const char * args)
4533 if(!*args)
4534 return false;
4536 std::string casename = args;
4538 AtLoginFlags atLogin;
4540 // Command specially created as single command to prevent using short case names
4541 if(casename=="spells")
4543 atLogin = AT_LOGIN_RESET_SPELLS;
4544 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4546 else if(casename=="talents")
4548 atLogin = AT_LOGIN_RESET_TALENTS;
4549 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4551 else
4553 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4554 SetSentErrorMessage(true);
4555 return false;
4558 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4559 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4560 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4561 itr->second->SetAtLoginFlag(atLogin);
4563 return true;
4566 bool ChatHandler::HandleShutDownCommand(const char* args)
4568 if(!*args)
4569 return false;
4571 if(std::string(args)=="cancel")
4573 sWorld.ShutdownCancel();
4575 else
4577 int32 time = atoi(args);
4579 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4580 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4581 return false;
4583 sWorld.ShutdownServ(time);
4585 return true;
4588 bool ChatHandler::HandleRestartCommand(const char* args)
4590 if(!*args)
4591 return false;
4593 if(std::string(args)=="cancel")
4595 sWorld.ShutdownCancel();
4597 else
4599 int32 time = atoi(args);
4601 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4602 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4603 return false;
4605 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4607 return true;
4610 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4612 if(!*args)
4613 return false;
4615 if(std::string(args)=="cancel")
4617 sWorld.ShutdownCancel();
4619 else
4621 int32 time = atoi(args);
4623 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4624 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4625 return false;
4627 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4629 return true;
4632 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4634 if(!*args)
4635 return false;
4637 if(std::string(args)=="cancel")
4639 sWorld.ShutdownCancel();
4641 else
4643 int32 time = atoi(args);
4645 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4646 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4647 return false;
4649 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4651 return true;
4654 bool ChatHandler::HandleAddQuest(const char* args)
4656 Player* player = getSelectedPlayer();
4657 if(!player)
4659 SendSysMessage(LANG_NO_CHAR_SELECTED);
4660 SetSentErrorMessage(true);
4661 return false;
4664 // .addquest #entry'
4665 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4666 char* cId = extractKeyFromLink((char*)args,"Hquest");
4667 if(!cId)
4668 return false;
4670 uint32 entry = atol(cId);
4672 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4674 if(!pQuest)
4676 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4677 SetSentErrorMessage(true);
4678 return false;
4681 // check item starting quest (it can work incorrectly if added without item in inventory)
4682 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4684 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4685 if (!pProto)
4686 continue;
4688 if (pProto->StartQuest == entry)
4690 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4691 SetSentErrorMessage(true);
4692 return false;
4696 // ok, normal (creature/GO starting) quest
4697 if( player->CanAddQuest( pQuest, true ) )
4699 player->AddQuest( pQuest, NULL );
4701 if ( player->CanCompleteQuest( entry ) )
4702 player->CompleteQuest( entry );
4705 return true;
4708 bool ChatHandler::HandleRemoveQuest(const char* args)
4710 Player* player = getSelectedPlayer();
4711 if(!player)
4713 SendSysMessage(LANG_NO_CHAR_SELECTED);
4714 SetSentErrorMessage(true);
4715 return false;
4718 // .removequest #entry'
4719 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4720 char* cId = extractKeyFromLink((char*)args,"Hquest");
4721 if(!cId)
4722 return false;
4724 uint32 entry = atol(cId);
4726 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4728 if(!pQuest)
4730 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4731 SetSentErrorMessage(true);
4732 return false;
4735 // remove all quest entries for 'entry' from quest log
4736 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4738 uint32 quest = player->GetQuestSlotQuestId(slot);
4739 if(quest==entry)
4741 player->SetQuestSlot(slot,0);
4743 // we ignore unequippable quest items in this case, its' still be equipped
4744 player->TakeQuestSourceItem( quest, false );
4748 // set quest status to not started (will updated in DB at next save)
4749 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4751 // reset rewarded for restart repeatable quest
4752 player->getQuestStatusMap()[entry].m_rewarded = false;
4754 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4755 return true;
4758 bool ChatHandler::HandleCompleteQuest(const char* args)
4760 Player* player = getSelectedPlayer();
4761 if(!player)
4763 SendSysMessage(LANG_NO_CHAR_SELECTED);
4764 SetSentErrorMessage(true);
4765 return false;
4768 // .quest complete #entry
4769 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4770 char* cId = extractKeyFromLink((char*)args,"Hquest");
4771 if(!cId)
4772 return false;
4774 uint32 entry = atol(cId);
4776 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4778 // If player doesn't have the quest
4779 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4781 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4782 SetSentErrorMessage(true);
4783 return false;
4786 // Add quest items for quests that require items
4787 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4789 uint32 id = pQuest->ReqItemId[x];
4790 uint32 count = pQuest->ReqItemCount[x];
4791 if(!id || !count)
4792 continue;
4794 uint32 curItemCount = player->GetItemCount(id,true);
4796 ItemPosCountVec dest;
4797 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4798 if( msg == EQUIP_ERR_OK )
4800 Item* item = player->StoreNewItem( dest, id, true);
4801 player->SendNewItem(item,count-curItemCount,true,false);
4805 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4806 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4808 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4809 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4811 if(uint32 spell_id = pQuest->ReqSpell[i])
4813 for(uint16 z = 0; z < creaturecount; ++z)
4814 player->CastedCreatureOrGO(creature,0,spell_id);
4816 else if(creature > 0)
4818 for(uint16 z = 0; z < creaturecount; ++z)
4819 player->KilledMonster(creature,0);
4821 else if(creature < 0)
4823 for(uint16 z = 0; z < creaturecount; ++z)
4824 player->CastedCreatureOrGO(creature,0,0);
4828 // If the quest requires reputation to complete
4829 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4831 uint32 repValue = pQuest->GetRepObjectiveValue();
4832 uint32 curRep = player->GetReputation(repFaction);
4833 if(curRep < repValue)
4835 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4836 player->SetFactionReputation(factionEntry,repValue);
4840 // If the quest requires money
4841 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4842 if(ReqOrRewMoney < 0)
4843 player->ModifyMoney(-ReqOrRewMoney);
4845 player->CompleteQuest(entry);
4846 return true;
4849 bool ChatHandler::HandleBanAccountCommand(const char* args)
4851 return HandleBanHelper(BAN_ACCOUNT,args);
4854 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4856 return HandleBanHelper(BAN_CHARACTER,args);
4859 bool ChatHandler::HandleBanIPCommand(const char* args)
4861 return HandleBanHelper(BAN_IP,args);
4864 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4866 if(!args)
4867 return false;
4869 char* cnameOrIP = strtok ((char*)args, " ");
4870 if (!cnameOrIP)
4871 return false;
4873 std::string nameOrIP = cnameOrIP;
4875 char* duration = strtok (NULL," ");
4876 if(!duration || !atoi(duration))
4877 return false;
4879 char* reason = strtok (NULL,"");
4880 if(!reason)
4881 return false;
4883 switch(mode)
4885 case BAN_ACCOUNT:
4886 if(!AccountMgr::normilizeString(nameOrIP))
4888 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4889 SetSentErrorMessage(true);
4890 return false;
4892 break;
4893 case BAN_CHARACTER:
4894 if(!normalizePlayerName(nameOrIP))
4896 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4897 SetSentErrorMessage(true);
4898 return false;
4900 break;
4901 case BAN_IP:
4902 if(!IsIPAddress(nameOrIP.c_str()))
4903 return false;
4904 break;
4907 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4909 case BAN_SUCCESS:
4910 if(atoi(duration)>0)
4911 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4912 else
4913 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4914 break;
4915 case BAN_SYNTAX_ERROR:
4916 return false;
4917 case BAN_NOTFOUND:
4918 switch(mode)
4920 default:
4921 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4922 break;
4923 case BAN_CHARACTER:
4924 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4925 break;
4926 case BAN_IP:
4927 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4928 break;
4930 SetSentErrorMessage(true);
4931 return false;
4934 return true;
4937 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4939 return HandleUnBanHelper(BAN_ACCOUNT,args);
4942 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4944 return HandleUnBanHelper(BAN_CHARACTER,args);
4947 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4949 return HandleUnBanHelper(BAN_IP,args);
4952 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4954 if(!args)
4955 return false;
4957 char* cnameOrIP = strtok ((char*)args, " ");
4958 if(!cnameOrIP)
4959 return false;
4961 std::string nameOrIP = cnameOrIP;
4963 switch(mode)
4965 case BAN_ACCOUNT:
4966 if(!AccountMgr::normilizeString(nameOrIP))
4968 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4969 SetSentErrorMessage(true);
4970 return false;
4972 break;
4973 case BAN_CHARACTER:
4974 if(!normalizePlayerName(nameOrIP))
4976 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4977 SetSentErrorMessage(true);
4978 return false;
4980 break;
4981 case BAN_IP:
4982 if(!IsIPAddress(nameOrIP.c_str()))
4983 return false;
4984 break;
4987 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4988 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4989 else
4990 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4992 return true;
4995 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
4997 if(!args)
4998 return false;
5000 char* cname = strtok((char*)args, "");
5001 if(!cname)
5002 return false;
5004 std::string account_name = cname;
5005 if(!AccountMgr::normilizeString(account_name))
5007 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5008 SetSentErrorMessage(true);
5009 return false;
5012 uint32 accountid = accmgr.GetId(account_name);
5013 if(!accountid)
5015 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5016 return true;
5019 return HandleBanInfoHelper(accountid,account_name.c_str());
5022 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5024 if(!args)
5025 return false;
5027 char* cname = strtok ((char*)args, "");
5028 if(!cname)
5029 return false;
5031 std::string name = cname;
5032 if(!normalizePlayerName(name))
5034 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5035 SetSentErrorMessage(true);
5036 return false;
5039 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5040 if(!accountid)
5042 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5043 SetSentErrorMessage(true);
5044 return false;
5047 std::string accountname;
5048 if(!accmgr.GetName(accountid,accountname))
5050 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5051 return true;
5054 return HandleBanInfoHelper(accountid,accountname.c_str());
5057 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5059 QueryResult *result = loginDatabase.PQuery("SELECT FROM_UNIXTIME(bandate), unbandate-bandate, active, unbandate,banreason,bannedby FROM account_banned WHERE id = '%u' ORDER BY bandate ASC",accountid);
5060 if(!result)
5062 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5063 return true;
5066 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5069 Field* fields = result->Fetch();
5071 time_t unbandate = time_t(fields[3].GetUInt64());
5072 bool active = false;
5073 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5074 active = true;
5075 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5076 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5077 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5078 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5079 }while (result->NextRow());
5081 delete result;
5082 return true;
5085 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5087 if(!args)
5088 return false;
5090 char* cIP = strtok ((char*)args, "");
5091 if(!cIP)
5092 return false;
5094 if (!IsIPAddress(cIP))
5095 return false;
5097 std::string IP = cIP;
5099 loginDatabase.escape_string(IP);
5100 QueryResult *result = loginDatabase.PQuery("SELECT ip, FROM_UNIXTIME(bandate), FROM_UNIXTIME(unbandate), unbandate-UNIX_TIMESTAMP(), banreason,bannedby,unbandate-bandate FROM ip_banned WHERE ip = '%s'",IP.c_str());
5101 if(!result)
5103 PSendSysMessage(LANG_BANINFO_NOIP);
5104 return true;
5107 Field *fields = result->Fetch();
5108 bool permanent = !fields[6].GetUInt64();
5109 PSendSysMessage(LANG_BANINFO_IPENTRY,
5110 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5111 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5112 delete result;
5113 return true;
5116 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5118 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5120 char* cFilter = strtok ((char*)args, " ");
5121 if(!cFilter)
5122 return false;
5124 std::string filter = cFilter;
5125 loginDatabase.escape_string(filter);
5126 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5127 if (!result)
5129 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5130 return true;
5133 return HandleBanListHelper(result);
5136 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5138 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5140 char* cFilter = strtok((char*)args, " ");
5141 std::string filter = cFilter ? cFilter : "";
5142 loginDatabase.escape_string(filter);
5144 QueryResult* result;
5146 if(filter.empty())
5148 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5149 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5151 else
5153 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5154 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5155 filter.c_str());
5158 if (!result)
5160 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5161 return true;
5164 return HandleBanListHelper(result);
5167 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5169 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5171 // Chat short output
5172 if(m_session)
5176 Field* fields = result->Fetch();
5177 uint32 accountid = fields[0].GetUInt32();
5179 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5180 if(banresult)
5182 Field* fields2 = banresult->Fetch();
5183 PSendSysMessage("%s",fields2[0].GetString());
5184 delete banresult;
5186 } while (result->NextRow());
5188 // Console wide output
5189 else
5191 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5192 SendSysMessage("===============================================================================");
5193 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5196 SendSysMessage("-------------------------------------------------------------------------------");
5197 Field *fields = result->Fetch();
5198 uint32 account_id = fields[0].GetUInt32 ();
5200 std::string account_name;
5202 // "account" case, name can be get in same query
5203 if(result->GetFieldCount() > 1)
5204 account_name = fields[1].GetCppString();
5205 // "character" case, name need extract from another DB
5206 else
5207 accmgr.GetName (account_id,account_name);
5209 // No SQL injection. id is uint32.
5210 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5211 if (banInfo)
5213 Field *fields2 = banInfo->Fetch();
5216 time_t t_ban = fields2[0].GetUInt64();
5217 tm* aTm_ban = localtime(&t_ban);
5219 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5221 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5222 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5223 fields2[2].GetString(),fields2[3].GetString());
5225 else
5227 time_t t_unban = fields2[1].GetUInt64();
5228 tm* aTm_unban = localtime(&t_unban);
5229 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5230 account_name.c_str(),aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5231 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5232 fields2[2].GetString(),fields2[3].GetString());
5234 }while ( banInfo->NextRow() );
5235 delete banInfo;
5237 }while( result->NextRow() );
5238 SendSysMessage("===============================================================================");
5241 delete result;
5242 return true;
5245 bool ChatHandler::HandleBanListIPCommand(const char* args)
5247 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5249 char* cFilter = strtok((char*)args, " ");
5250 std::string filter = cFilter ? cFilter : "";
5251 loginDatabase.escape_string(filter);
5253 QueryResult* result;
5255 if(filter.empty())
5257 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5258 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5259 " ORDER BY unbandate" );
5261 else
5263 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5264 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5265 " ORDER BY unbandate",filter.c_str() );
5268 if(!result)
5270 PSendSysMessage(LANG_BANLIST_NOIP);
5271 return true;
5274 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5275 // Chat short output
5276 if(m_session)
5280 Field* fields = result->Fetch();
5281 PSendSysMessage("%s",fields[0].GetString());
5282 } while (result->NextRow());
5284 // Console wide output
5285 else
5287 SendSysMessage(LANG_BANLIST_IPS);
5288 SendSysMessage("===============================================================================");
5289 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5292 SendSysMessage("-------------------------------------------------------------------------------");
5293 Field *fields = result->Fetch();
5294 time_t t_ban = fields[1].GetUInt64();
5295 tm* aTm_ban = localtime(&t_ban);
5296 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5298 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5299 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5300 fields[3].GetString(), fields[4].GetString());
5302 else
5304 time_t t_unban = fields[2].GetUInt64();
5305 tm* aTm_unban = localtime(&t_unban);
5306 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5307 fields[0].GetString(), aTm_ban->tm_year%100, aTm_ban->tm_mon+1, aTm_ban->tm_mday, aTm_ban->tm_hour, aTm_ban->tm_min,
5308 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5309 fields[3].GetString(), fields[4].GetString());
5311 }while( result->NextRow() );
5312 SendSysMessage("===============================================================================");
5315 delete result;
5316 return true;
5319 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5321 Player* pl = m_session->GetPlayer();
5323 // accept only explicitly selected target (not implicitly self targeting case)
5324 Unit* target = getSelectedUnit();
5325 if(pl->GetSelection() && target)
5327 if(target->GetTypeId()!=TYPEID_UNIT)
5329 SendSysMessage(LANG_SELECT_CREATURE);
5330 SetSentErrorMessage(true);
5331 return false;
5334 if(target->isDead())
5335 ((Creature*)target)->Respawn();
5336 return true;
5339 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5340 Cell cell(p);
5341 cell.data.Part.reserved = ALL_DISTRICT;
5342 cell.SetNoCreate();
5344 MaNGOS::RespawnDo u_do;
5345 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5347 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5348 CellLock<GridReadGuard> cell_lock(cell, p);
5349 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5351 return true;
5354 bool ChatHandler::HandleFlyModeCommand(const char* args)
5356 if(!args)
5357 return false;
5359 Unit *unit = getSelectedUnit();
5360 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5361 unit = m_session->GetPlayer();
5363 WorldPacket data(12);
5364 if (strncmp(args, "on", 3) == 0)
5365 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5366 else if (strncmp(args, "off", 4) == 0)
5367 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5368 else
5370 SendSysMessage(LANG_USE_BOL);
5371 return false;
5373 data.append(unit->GetPackGUID());
5374 data << uint32(0); // unknown
5375 unit->SendMessageToSet(&data, true);
5376 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5377 return true;
5380 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5382 if(!args)
5383 return false;
5385 char * file = strtok((char*)args, " ");
5386 if(!file)
5387 return false;
5389 char * account = strtok(NULL, " ");
5390 if(!account)
5391 return false;
5393 std::string account_name = account;
5394 if(!AccountMgr::normilizeString(account_name))
5396 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5397 SetSentErrorMessage(true);
5398 return false;
5401 uint32 account_id = accmgr.GetId(account_name);
5402 if(!account_id)
5404 account_id = atoi(account); // use original string
5405 if(!account_id)
5407 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5408 SetSentErrorMessage(true);
5409 return false;
5413 if(!accmgr.GetName(account_id,account_name))
5415 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5416 SetSentErrorMessage(true);
5417 return false;
5420 char* guid_str = NULL;
5421 char* name_str = strtok(NULL, " ");
5423 std::string name;
5424 if(name_str)
5426 name = name_str;
5427 // normalize the name if specified and check if it exists
5428 if(!normalizePlayerName(name))
5430 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5431 SetSentErrorMessage(true);
5432 return false;
5435 if(!ObjectMgr::IsValidName(name,true))
5437 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5438 SetSentErrorMessage(true);
5439 return false;
5442 guid_str = strtok(NULL, " ");
5445 uint32 guid = 0;
5447 if(guid_str)
5449 guid = atoi(guid_str);
5450 if(!guid)
5452 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5453 SetSentErrorMessage(true);
5454 return false;
5457 if(objmgr.GetPlayerAccountIdByGUID(guid))
5459 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5460 SetSentErrorMessage(true);
5461 return false;
5465 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5467 case DUMP_SUCCESS:
5468 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5469 break;
5470 case DUMP_FILE_OPEN_ERROR:
5471 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5472 SetSentErrorMessage(true);
5473 return false;
5474 case DUMP_FILE_BROKEN:
5475 PSendSysMessage(LANG_DUMP_BROKEN,file);
5476 SetSentErrorMessage(true);
5477 return false;
5478 case DUMP_TOO_MANY_CHARS:
5479 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5480 SetSentErrorMessage(true);
5481 return false;
5482 default:
5483 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5484 SetSentErrorMessage(true);
5485 return false;
5488 return true;
5491 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
5493 if(!args)
5494 return false;
5496 uint32 newEntryNum = atoi(args);
5497 if(!newEntryNum)
5498 return false;
5500 Unit* unit = getSelectedUnit();
5501 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5503 SendSysMessage(LANG_SELECT_CREATURE);
5504 SetSentErrorMessage(true);
5505 return false;
5507 Creature* creature = (Creature*)unit;
5508 if(creature->UpdateEntry(newEntryNum))
5509 SendSysMessage(LANG_DONE);
5510 else
5511 SendSysMessage(LANG_ERROR);
5512 return true;
5515 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5517 if(!args)
5518 return false;
5520 char* file = strtok((char*)args, " ");
5521 char* p2 = strtok(NULL, " ");
5523 if(!file || !p2)
5524 return false;
5526 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5527 if(!guid)
5528 guid = atoi(p2);
5530 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5532 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5533 SetSentErrorMessage(true);
5534 return false;
5537 switch(PlayerDumpWriter().WriteDump(file, guid))
5539 case DUMP_SUCCESS:
5540 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5541 break;
5542 case DUMP_FILE_OPEN_ERROR:
5543 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5544 SetSentErrorMessage(true);
5545 return false;
5546 default:
5547 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5548 SetSentErrorMessage(true);
5549 return false;
5552 return true;
5555 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5557 Unit* unit = getSelectedUnit();
5558 if(!unit)
5560 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5561 SetSentErrorMessage(true);
5562 return false;
5565 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5567 MotionMaster* mm = unit->GetMotionMaster();
5568 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5570 switch((*itr)->GetMovementGeneratorType())
5572 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5573 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5574 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5575 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5576 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5577 case TARGETED_MOTION_TYPE:
5579 if(unit->GetTypeId()==TYPEID_PLAYER)
5581 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5582 Unit* target = mgen->GetTarget();
5583 if(target)
5584 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5585 else
5586 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5588 else
5590 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5591 Unit* target = mgen->GetTarget();
5592 if(target)
5593 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5594 else
5595 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5597 break;
5599 case HOME_MOTION_TYPE:
5600 if(unit->GetTypeId()==TYPEID_UNIT)
5602 float x,y,z;
5603 (*itr)->GetDestination(x,y,z);
5604 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5606 else
5607 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5608 break;
5609 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5610 case POINT_MOTION_TYPE:
5612 float x,y,z;
5613 (*itr)->GetDestination(x,y,z);
5614 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5615 break;
5617 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5618 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5619 default:
5620 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5621 break;
5624 return true;
5627 bool ChatHandler::HandlePLimitCommand(const char *args)
5629 if(*args)
5631 char* param = strtok((char*)args, " ");
5632 if(!param)
5633 return false;
5635 int l = strlen(param);
5637 if( strncmp(param,"player",l) == 0 )
5638 sWorld.SetPlayerLimit(-SEC_PLAYER);
5639 else if(strncmp(param,"moderator",l) == 0 )
5640 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5641 else if(strncmp(param,"gamemaster",l) == 0 )
5642 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5643 else if(strncmp(param,"administrator",l) == 0 )
5644 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5645 else if(strncmp(param,"reset",l) == 0 )
5646 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5647 else
5649 int val = atoi(param);
5650 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5652 sWorld.SetPlayerLimit(val);
5655 // kick all low security level players
5656 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5657 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5660 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5661 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5662 char const* secName = "";
5663 switch(allowedAccountType)
5665 case SEC_PLAYER: secName = "Player"; break;
5666 case SEC_MODERATOR: secName = "Moderator"; break;
5667 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5668 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5669 default: secName = "<unknown>"; break;
5672 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5674 return true;
5677 bool ChatHandler::HandleCastCommand(const char* args)
5679 if(!*args)
5680 return false;
5682 Unit* target = getSelectedUnit();
5684 if(!target)
5686 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5687 SetSentErrorMessage(true);
5688 return false;
5691 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5692 uint32 spell = extractSpellIdFromLink((char*)args);
5693 if(!spell)
5694 return false;
5696 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5697 if(!spellInfo)
5698 return false;
5700 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5702 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5703 SetSentErrorMessage(true);
5704 return false;
5707 char* trig_str = strtok(NULL, " ");
5708 if(trig_str)
5710 int l = strlen(trig_str);
5711 if(strncmp(trig_str,"triggered",l) != 0 )
5712 return false;
5715 bool triggered = (trig_str != NULL);
5717 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5719 return true;
5722 bool ChatHandler::HandleCastBackCommand(const char* args)
5724 Creature* caster = getSelectedCreature();
5726 if(!caster)
5728 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5729 SetSentErrorMessage(true);
5730 return false;
5733 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5734 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5735 uint32 spell = extractSpellIdFromLink((char*)args);
5736 if(!spell || !sSpellStore.LookupEntry(spell))
5737 return false;
5739 char* trig_str = strtok(NULL, " ");
5740 if(trig_str)
5742 int l = strlen(trig_str);
5743 if(strncmp(trig_str,"triggered",l) != 0 )
5744 return false;
5747 bool triggered = (trig_str != NULL);
5749 // update orientation at server
5750 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5752 // and client
5753 WorldPacket data;
5754 caster->BuildHeartBeatMsg(&data);
5755 caster->SendMessageToSet(&data,true);
5757 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5759 return true;
5762 bool ChatHandler::HandleCastDistCommand(const char* args)
5764 if(!*args)
5765 return false;
5767 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5768 uint32 spell = extractSpellIdFromLink((char*)args);
5769 if(!spell)
5770 return false;
5772 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5773 if(!spellInfo)
5774 return false;
5776 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5778 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5779 SetSentErrorMessage(true);
5780 return false;
5783 char *distStr = strtok(NULL, " ");
5785 float dist = 0;
5787 if(distStr)
5788 sscanf(distStr, "%f", &dist);
5790 char* trig_str = strtok(NULL, " ");
5791 if(trig_str)
5793 int l = strlen(trig_str);
5794 if(strncmp(trig_str,"triggered",l) != 0 )
5795 return false;
5798 bool triggered = (trig_str != NULL);
5800 float x,y,z;
5801 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5803 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5804 return true;
5807 bool ChatHandler::HandleCastTargetCommand(const char* args)
5809 Creature* caster = getSelectedCreature();
5811 if(!caster)
5813 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5814 SetSentErrorMessage(true);
5815 return false;
5818 if(!caster->getVictim())
5820 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5821 SetSentErrorMessage(true);
5822 return false;
5825 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5826 uint32 spell = extractSpellIdFromLink((char*)args);
5827 if(!spell || !sSpellStore.LookupEntry(spell))
5828 return false;
5830 char* trig_str = strtok(NULL, " ");
5831 if(trig_str)
5833 int l = strlen(trig_str);
5834 if(strncmp(trig_str,"triggered",l) != 0 )
5835 return false;
5838 bool triggered = (trig_str != NULL);
5840 // update orientation at server
5841 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5843 // and client
5844 WorldPacket data;
5845 caster->BuildHeartBeatMsg(&data);
5846 caster->SendMessageToSet(&data,true);
5848 caster->CastSpell(caster->getVictim(),spell,triggered);
5850 return true;
5854 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5855 Without this function 3rd party scripting library will get linking errors (unresolved external)
5856 when attempting to use the PointMovementGenerator
5858 bool ChatHandler::HandleComeToMeCommand(const char *args)
5860 Creature* caster = getSelectedCreature();
5862 if(!caster)
5864 SendSysMessage(LANG_SELECT_CREATURE);
5865 SetSentErrorMessage(true);
5866 return false;
5869 char* newFlagStr = strtok((char*)args, " ");
5871 if(!newFlagStr)
5872 return false;
5874 uint32 newFlags = atoi(newFlagStr);
5876 caster->SetUnitMovementFlags(newFlags);
5878 Player* pl = m_session->GetPlayer();
5880 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5881 return true;
5884 bool ChatHandler::HandleCastSelfCommand(const char* args)
5886 if(!*args)
5887 return false;
5889 Unit* target = getSelectedUnit();
5891 if(!target)
5893 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5894 SetSentErrorMessage(true);
5895 return false;
5898 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5899 uint32 spell = extractSpellIdFromLink((char*)args);
5900 if(!spell)
5901 return false;
5903 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5904 if(!spellInfo)
5905 return false;
5907 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5909 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5910 SetSentErrorMessage(true);
5911 return false;
5914 target->CastSpell(target,spell,false);
5916 return true;
5919 std::string GetTimeString(uint32 time)
5921 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5922 std::ostringstream ss;
5923 if(days) ss << days << "d ";
5924 if(hours) ss << hours << "h ";
5925 ss << minute << "m";
5926 return ss.str();
5929 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5931 Player* player = getSelectedPlayer();
5932 if (!player) player = m_session->GetPlayer();
5933 uint32 counter = 0;
5934 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5936 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5937 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5939 InstanceSave *save = itr->second.save;
5940 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5941 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5942 counter++;
5945 PSendSysMessage("player binds: %d", counter);
5946 counter = 0;
5947 Group *group = player->GetGroup();
5948 if(group)
5950 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5952 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5953 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5955 InstanceSave *save = itr->second.save;
5956 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5957 PSendSysMessage("map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5958 counter++;
5962 PSendSysMessage("group binds: %d", counter);
5964 return true;
5967 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5969 if(!*args)
5970 return false;
5972 std::string cmd = args;
5973 if(cmd == "all")
5975 Player* player = getSelectedPlayer();
5976 if (!player) player = m_session->GetPlayer();
5977 uint32 counter = 0;
5978 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5980 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5981 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5983 if(itr->first != player->GetMapId())
5985 InstanceSave *save = itr->second.save;
5986 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5987 PSendSysMessage("unbinding map: %d inst: %d perm: %s diff: %s canReset: %s TTR: %s", itr->first, save->GetInstanceId(), itr->second.perm ? "yes" : "no", save->GetDifficulty() == DIFFICULTY_NORMAL ? "normal" : "heroic", save->CanReset() ? "yes" : "no", timeleft.c_str());
5988 player->UnbindInstance(itr, i);
5989 counter++;
5991 else
5992 ++itr;
5995 PSendSysMessage("instances unbound: %d", counter);
5997 return true;
6000 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6002 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6003 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6004 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6005 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6006 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6007 return true;
6010 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6012 Player* pl = m_session->GetPlayer();
6014 Map* map = pl->GetMap();
6015 if (!map->IsDungeon())
6017 PSendSysMessage("Map is not a dungeon.");
6018 SetSentErrorMessage(true);
6019 return false;
6022 if (!((InstanceMap*)map)->GetInstanceData())
6024 PSendSysMessage("Map has no instance data.");
6025 SetSentErrorMessage(true);
6026 return false;
6029 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6030 return true;
6033 /// Display the list of GMs
6034 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6036 ///- Get the accounts with GM Level >0
6037 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6038 if(result)
6040 SendSysMessage(LANG_GMLIST);
6041 SendSysMessage("========================");
6042 SendSysMessage(LANG_GMLIST_HEADER);
6043 SendSysMessage("========================");
6045 ///- Circle through them. Display username and GM level
6048 Field *fields = result->Fetch();
6049 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6050 }while( result->NextRow() );
6052 PSendSysMessage("========================");
6053 delete result;
6055 else
6056 PSendSysMessage(LANG_GMLIST_EMPTY);
6057 return true;
6060 /// Define the 'Message of the day' for the realm
6061 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6063 sWorld.SetMotd(args);
6064 PSendSysMessage(LANG_MOTD_NEW, args);
6065 return true;
6068 /// Set/Unset the expansion level for an account
6069 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6071 ///- Get the command line arguments
6072 char *szAcc = strtok((char*)args," ");
6073 char *szExp = strtok(NULL," ");
6075 if(!szAcc)
6076 return false;
6078 std::string account_name;
6079 uint32 account_id;
6081 if(!szExp)
6083 Player* player = getSelectedPlayer();
6084 if(!player)
6085 return false;
6087 account_id = player->GetSession()->GetAccountId();
6088 accmgr.GetName(account_id,account_name);
6089 szExp = szAcc;
6091 else
6093 ///- Convert Account name to Upper Format
6094 account_name = szAcc;
6095 if(!AccountMgr::normilizeString(account_name))
6097 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6098 SetSentErrorMessage(true);
6099 return false;
6102 account_id = accmgr.GetId(account_name);
6103 if(!account_id)
6105 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6106 SetSentErrorMessage(true);
6107 return false;
6111 int lev=atoi(szExp); //get int anyway (0 if error)
6112 if(lev < 0)
6113 return false;
6115 // No SQL injection
6116 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6117 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6118 return true;
6121 //Send items by mail
6122 bool ChatHandler::HandleSendItemsCommand(const char* args)
6124 if(!*args)
6125 return false;
6127 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6129 char* pName = strtok((char*)args, " ");
6130 if(!pName)
6131 return false;
6133 char* tail1 = strtok(NULL, "");
6134 if(!tail1)
6135 return false;
6137 char* msgSubject;
6138 if(*tail1=='"')
6139 msgSubject = strtok(tail1+1, "\"");
6140 else
6142 char* space = strtok(tail1, "\"");
6143 if(!space)
6144 return false;
6145 msgSubject = strtok(NULL, "\"");
6148 if (!msgSubject)
6149 return false;
6151 char* tail2 = strtok(NULL, "");
6152 if(!tail2)
6153 return false;
6155 char* msgText;
6156 if(*tail2=='"')
6157 msgText = strtok(tail2+1, "\"");
6158 else
6160 char* space = strtok(tail2, "\"");
6161 if(!space)
6162 return false;
6163 msgText = strtok(NULL, "\"");
6166 if (!msgText)
6167 return false;
6169 // pName, msgSubject, msgText isn't NUL after prev. check
6170 std::string name = pName;
6171 std::string subject = msgSubject;
6172 std::string text = msgText;
6174 // extract items
6175 typedef std::pair<uint32,uint32> ItemPair;
6176 typedef std::list< ItemPair > ItemPairs;
6177 ItemPairs items;
6179 // get all tail string
6180 char* tail = strtok(NULL, "");
6182 // get from tail next item str
6183 while(char* itemStr = strtok(tail, " "))
6185 // and get new tail
6186 tail = strtok(NULL, "");
6188 // parse item str
6189 char* itemIdStr = strtok(itemStr, ":");
6190 char* itemCountStr = strtok(NULL, " ");
6192 uint32 item_id = atoi(itemIdStr);
6193 if(!item_id)
6194 return false;
6196 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6197 if(!item_proto)
6199 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6200 SetSentErrorMessage(true);
6201 return false;
6204 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6205 if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
6207 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6208 SetSentErrorMessage(true);
6209 return false;
6212 while(item_count > item_proto->Stackable)
6214 items.push_back(ItemPair(item_id,item_proto->Stackable));
6215 item_count -= item_proto->Stackable;
6218 items.push_back(ItemPair(item_id,item_count));
6220 if(items.size() > MAX_MAIL_ITEMS)
6222 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6223 SetSentErrorMessage(true);
6224 return false;
6228 if(!normalizePlayerName(name))
6230 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6231 SetSentErrorMessage(true);
6232 return false;
6235 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6236 if(!receiver_guid)
6238 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6239 SetSentErrorMessage(true);
6240 return false;
6243 // from console show not existed sender
6244 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6246 uint32 messagetype = MAIL_NORMAL;
6247 uint32 stationery = MAIL_STATIONERY_GM;
6248 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6250 Player *receiver = objmgr.GetPlayer(receiver_guid);
6252 // fill mail
6253 MailItemsInfo mi; // item list preparing
6255 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6257 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6259 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6260 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6264 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6266 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
6267 return true;
6270 ///Send money by mail
6271 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6273 if (!*args)
6274 return false;
6276 /// format: name "subject text" "mail text" money
6278 char* pName = strtok((char*)args, " ");
6279 if (!pName)
6280 return false;
6282 char* tail1 = strtok(NULL, "");
6283 if (!tail1)
6284 return false;
6286 char* msgSubject;
6287 if (*tail1=='"')
6288 msgSubject = strtok(tail1+1, "\"");
6289 else
6291 char* space = strtok(tail1, "\"");
6292 if (!space)
6293 return false;
6294 msgSubject = strtok(NULL, "\"");
6297 if (!msgSubject)
6298 return false;
6300 char* tail2 = strtok(NULL, "");
6301 if (!tail2)
6302 return false;
6304 char* msgText;
6305 if (*tail2=='"')
6306 msgText = strtok(tail2+1, "\"");
6307 else
6309 char* space = strtok(tail2, "\"");
6310 if (!space)
6311 return false;
6312 msgText = strtok(NULL, "\"");
6315 if (!msgText)
6316 return false;
6318 int32 money = atoi(strtok(NULL, ""));
6319 if (money <= 0)
6320 return false;
6322 // pName, msgSubject, msgText isn't NUL after prev. check
6323 std::string name = pName;
6324 std::string subject = msgSubject;
6325 std::string text = msgText;
6327 if (!normalizePlayerName(name))
6329 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6330 SetSentErrorMessage(true);
6331 return false;
6334 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6335 if (!receiver_guid)
6337 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6338 SetSentErrorMessage(true);
6339 return false;
6342 uint32 mailId = objmgr.GenerateMailID();
6344 // from console show not existed sender
6345 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6347 uint32 messagetype = MAIL_NORMAL;
6348 uint32 stationery = MAIL_STATIONERY_GM;
6349 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6351 Player *receiver = objmgr.GetPlayer(receiver_guid);
6353 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6355 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
6356 return true;
6359 /// Send a message to a player in game
6360 bool ChatHandler::HandleSendMessageCommand(const char* args)
6362 ///- Get the command line arguments
6363 char* name_str = strtok((char*)args, " ");
6364 char* msg_str = strtok(NULL, "");
6366 if(!name_str || !msg_str)
6367 return false;
6369 std::string name = name_str;
6371 if(!normalizePlayerName(name))
6372 return false;
6374 ///- Find the player and check that he is not logging out.
6375 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6376 if(!rPlayer)
6378 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6379 SetSentErrorMessage(true);
6380 return false;
6383 if(rPlayer->GetSession()->isLogingOut())
6385 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6386 SetSentErrorMessage(true);
6387 return false;
6390 ///- Send the message
6391 //Use SendAreaTriggerMessage for fastest delivery.
6392 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6393 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6395 //Confirmation message
6396 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6397 return true;
6400 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6402 if(!*args)
6403 return false;
6405 Player *player = getSelectedPlayer();
6407 if(!player)
6409 PSendSysMessage(LANG_NO_PLAYER);
6410 SetSentErrorMessage(true);
6411 return false;
6414 char const* gender_str = (char*)args;
6415 int gender_len = strlen(gender_str);
6417 uint32 displayId = player->GetNativeDisplayId();
6418 char const* gender_full = NULL;
6419 uint32 new_displayId = displayId;
6420 Gender gender;
6422 if(!strncmp(gender_str,"male",gender_len)) // MALE
6424 if(player->getGender() == GENDER_MALE)
6425 return true;
6427 gender_full = "male";
6428 new_displayId = player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1;
6429 gender = GENDER_MALE;
6431 else if (!strncmp(gender_str,"female",gender_len)) // FEMALE
6433 if(player->getGender() == GENDER_FEMALE)
6434 return true;
6436 gender_full = "female";
6437 new_displayId = player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1;
6438 gender = GENDER_FEMALE;
6440 else
6442 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6443 SetSentErrorMessage(true);
6444 return false;
6447 // Set gender
6448 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6450 // Change display ID
6451 player->SetDisplayId(new_displayId);
6452 player->SetNativeDisplayId(new_displayId);
6454 PSendSysMessage(LANG_YOU_CHANGE_GENDER, player->GetName(),gender_full);
6455 if (needReportToTarget(player))
6456 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full,GetName());
6457 return true;