[6810] Added new command: .sendmoney player "subject" "message" money - Sends a mail...
[getmangos.git] / src / game / Level3.cpp
blob14de327813dcc73fca97f83cdf28475f96a20b72
1 /*
2 * Copyright (C) 2005-2008 MaNGOS <http://getmangos.com/>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include "Common.h"
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
23 #include "World.h"
24 #include "ObjectMgr.h"
25 #include "AccountMgr.h"
26 #include "PlayerDump.h"
27 #include "SpellMgr.h"
28 #include "Player.h"
29 #include "Opcodes.h"
30 #include "GameObject.h"
31 #include "Chat.h"
32 #include "Log.h"
33 #include "Guild.h"
34 #include "ObjectAccessor.h"
35 #include "MapManager.h"
36 #include "SpellAuras.h"
37 #include "ScriptCalls.h"
38 #include "Language.h"
39 #include "GridNotifiersImpl.h"
40 #include "CellImpl.h"
41 #include "Weather.h"
42 #include "PointMovementGenerator.h"
43 #include "TargetedMovementGenerator.h"
44 #include "SkillDiscovery.h"
45 #include "SkillExtraItems.h"
46 #include "SystemConfig.h"
47 #include "Config/ConfigEnv.h"
48 #include "Util.h"
49 #include "ItemEnchantmentMgr.h"
50 #include "InstanceSaveMgr.h"
51 #include "InstanceData.h"
53 //reload commands
54 bool ChatHandler::HandleReloadCommand(const char* arg)
56 // this is error catcher for wrong table name in .reload commands
57 PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg);
58 SetSentErrorMessage(true);
59 return false;
62 bool ChatHandler::HandleReloadAllCommand(const char*)
64 HandleReloadAreaTriggerTeleportCommand("");
65 HandleReloadSkillFishingBaseLevelCommand("");
67 HandleReloadAllAreaCommand("");
68 HandleReloadAllLootCommand("");
69 HandleReloadAllNpcCommand("");
70 HandleReloadAllQuestCommand("");
71 HandleReloadAllSpellCommand("");
72 HandleReloadAllItemCommand("");
73 HandleReloadAllLocalesCommand("");
75 HandleReloadCommandCommand("");
76 HandleReloadReservedNameCommand("");
77 HandleReloadMangosStringCommand("");
78 HandleReloadGameTeleCommand("");
79 return true;
82 bool ChatHandler::HandleReloadAllAreaCommand(const char*)
84 //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
85 HandleReloadAreaTriggerTeleportCommand("");
86 HandleReloadAreaTriggerTavernCommand("");
87 HandleReloadGameGraveyardZoneCommand("");
88 return true;
91 bool ChatHandler::HandleReloadAllLootCommand(const char*)
93 sLog.outString( "Re-Loading Loot Tables..." );
94 LoadLootTables();
95 SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
96 return true;
99 bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
101 HandleReloadNpcGossipCommand("a");
102 HandleReloadNpcOptionCommand("a");
103 HandleReloadNpcTrainerCommand("a");
104 HandleReloadNpcVendorCommand("a");
105 return true;
108 bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
110 HandleReloadQuestAreaTriggersCommand("a");
111 HandleReloadQuestTemplateCommand("a");
113 sLog.outString( "Re-Loading Quests Relations..." );
114 objmgr.LoadQuestRelations();
115 SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
116 return true;
119 bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
121 if(sWorld.IsScriptScheduled())
123 PSendSysMessage("DB scripts used currently, please attempt reload later.");
124 SetSentErrorMessage(true);
125 return false;
128 sLog.outString( "Re-Loading Scripts..." );
129 HandleReloadGameObjectScriptsCommand("a");
130 HandleReloadEventScriptsCommand("a");
131 HandleReloadQuestEndScriptsCommand("a");
132 HandleReloadQuestStartScriptsCommand("a");
133 HandleReloadSpellScriptsCommand("a");
134 SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
135 return true;
138 bool ChatHandler::HandleReloadAllSpellCommand(const char*)
140 HandleReloadSkillDiscoveryTemplateCommand("a");
141 HandleReloadSkillExtraItemTemplateCommand("a");
142 HandleReloadSpellAffectCommand("a");
143 HandleReloadSpellChainCommand("a");
144 HandleReloadSpellElixirCommand("a");
145 HandleReloadSpellLearnSpellCommand("a");
146 HandleReloadSpellProcEventCommand("a");
147 HandleReloadSpellScriptTargetCommand("a");
148 HandleReloadSpellTargetPositionCommand("a");
149 HandleReloadSpellThreatsCommand("a");
150 HandleReloadSpellPetAurasCommand("a");
151 return true;
154 bool ChatHandler::HandleReloadAllItemCommand(const char*)
156 HandleReloadPageTextsCommand("a");
157 HandleReloadItemEnchantementsCommand("a");
158 return true;
161 bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
163 HandleReloadLocalesCreatureCommand("a");
164 HandleReloadLocalesGameobjectCommand("a");
165 HandleReloadLocalesItemCommand("a");
166 HandleReloadLocalesNpcTextCommand("a");
167 HandleReloadLocalesPageTextCommand("a");
168 HandleReloadLocalesQuestCommand("a");
169 return true;
172 bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
174 sLog.outString( "Re-Loading config settings..." );
175 sWorld.LoadConfigSettings(true);
176 SendGlobalSysMessage("World config settings reloaded.");
177 return true;
180 bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
182 sLog.outString( "Re-Loading Tavern Area Triggers..." );
183 objmgr.LoadTavernAreaTriggers();
184 SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
185 return true;
188 bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
190 sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
191 objmgr.LoadAreaTriggerTeleports();
192 SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
193 return true;
196 bool ChatHandler::HandleReloadCommandCommand(const char*)
198 load_command_table = true;
199 SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
200 return true;
203 bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
205 sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
206 objmgr.LoadCreatureQuestRelations();
207 SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
208 return true;
211 bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
213 sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
214 objmgr.LoadCreatureInvolvedRelations();
215 SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
216 return true;
219 bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
221 sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
222 objmgr.LoadGameobjectQuestRelations();
223 SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
224 return true;
227 bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
229 sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
230 objmgr.LoadGameobjectInvolvedRelations();
231 SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
232 return true;
235 bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
237 sLog.outString( "Re-Loading Quest Area Triggers..." );
238 objmgr.LoadQuestAreaTriggers();
239 SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
240 return true;
243 bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
245 sLog.outString( "Re-Loading Quest Templates..." );
246 objmgr.LoadQuests();
247 SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
248 return true;
251 bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
253 sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
254 LoadLootTemplates_Creature();
255 LootTemplates_Creature.CheckLootRefs();
256 SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
257 return true;
260 bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
262 sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
263 LoadLootTemplates_Disenchant();
264 LootTemplates_Disenchant.CheckLootRefs();
265 SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
266 return true;
269 bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
271 sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
272 LoadLootTemplates_Fishing();
273 LootTemplates_Fishing.CheckLootRefs();
274 SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
275 return true;
278 bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
280 sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
281 LoadLootTemplates_Gameobject();
282 LootTemplates_Gameobject.CheckLootRefs();
283 SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
284 return true;
287 bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
289 sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
290 LoadLootTemplates_Item();
291 LootTemplates_Item.CheckLootRefs();
292 SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
293 return true;
296 bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
298 sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
299 LoadLootTemplates_Pickpocketing();
300 LootTemplates_Pickpocketing.CheckLootRefs();
301 SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
302 return true;
305 bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
307 sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
308 LoadLootTemplates_Prospecting();
309 LootTemplates_Prospecting.CheckLootRefs();
310 SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
311 return true;
314 bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
316 sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
317 LoadLootTemplates_QuestMail();
318 LootTemplates_QuestMail.CheckLootRefs();
319 SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
320 return true;
323 bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
325 sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
326 LoadLootTemplates_Reference();
327 SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
328 return true;
331 bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
333 sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
334 LoadLootTemplates_Skinning();
335 LootTemplates_Skinning.CheckLootRefs();
336 SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
337 return true;
340 bool ChatHandler::HandleReloadMangosStringCommand(const char*)
342 sLog.outString( "Re-Loading mangos_string Table!" );
343 objmgr.LoadMangosStrings();
344 SendGlobalSysMessage("DB table `mangos_string` reloaded.");
345 return true;
348 bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
350 sLog.outString( "Re-Loading `npc_option` Table!" );
351 objmgr.LoadNpcOptions();
352 SendGlobalSysMessage("DB table `npc_option` reloaded.");
353 return true;
356 bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
358 sLog.outString( "Re-Loading `npc_gossip` Table!" );
359 objmgr.LoadNpcTextId();
360 SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
361 return true;
364 bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
366 sLog.outString( "Re-Loading `npc_trainer` Table!" );
367 objmgr.LoadTrainerSpell();
368 SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
369 return true;
372 bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
374 sLog.outString( "Re-Loading `npc_vendor` Table!" );
375 objmgr.LoadVendors();
376 SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
377 return true;
380 bool ChatHandler::HandleReloadReservedNameCommand(const char*)
382 sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
383 objmgr.LoadReservedPlayersNames();
384 SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
385 return true;
388 bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
390 sLog.outString( "Re-Loading Skill Discovery Table..." );
391 LoadSkillDiscoveryTable();
392 SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
393 return true;
396 bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
398 sLog.outString( "Re-Loading Skill Extra Item Table..." );
399 LoadSkillExtraItemTable();
400 SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
401 return true;
404 bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
406 sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
407 objmgr.LoadFishingBaseSkillLevel();
408 SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
409 return true;
412 bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
414 sLog.outString( "Re-Loading SpellAffect definitions..." );
415 spellmgr.LoadSpellAffects();
416 SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
417 return true;
420 bool ChatHandler::HandleReloadSpellChainCommand(const char*)
422 sLog.outString( "Re-Loading Spell Chain Data... " );
423 spellmgr.LoadSpellChains();
424 SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
425 return true;
428 bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
430 sLog.outString( "Re-Loading Spell Elixir types..." );
431 spellmgr.LoadSpellElixirs();
432 SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
433 return true;
436 bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
438 sLog.outString( "Re-Loading Spell Learn Spells..." );
439 spellmgr.LoadSpellLearnSpells();
440 SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
441 return true;
444 bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
446 sLog.outString( "Re-Loading Spell Proc Event conditions..." );
447 spellmgr.LoadSpellProcEvents();
448 SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
449 return true;
452 bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
454 sLog.outString( "Re-Loading SpellsScriptTarget..." );
455 spellmgr.LoadSpellScriptTarget();
456 SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
457 return true;
460 bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
462 sLog.outString( "Re-Loading Spell target coordinates..." );
463 spellmgr.LoadSpellTargetPositions();
464 SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
465 return true;
468 bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
470 sLog.outString( "Re-Loading Aggro Spells Definitions...");
471 spellmgr.LoadSpellThreats();
472 SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
473 return true;
476 bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
478 sLog.outString( "Re-Loading Spell pet auras...");
479 spellmgr.LoadSpellPetAuras();
480 SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
481 return true;
484 bool ChatHandler::HandleReloadPageTextsCommand(const char*)
486 sLog.outString( "Re-Loading Page Texts..." );
487 objmgr.LoadPageTexts();
488 SendGlobalSysMessage("DB table `page_texts` reloaded.");
489 return true;
492 bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
494 sLog.outString( "Re-Loading Item Random Enchantments Table..." );
495 LoadRandomEnchantmentsTable();
496 SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
497 return true;
500 bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
502 if(sWorld.IsScriptScheduled())
504 SendSysMessage("DB scripts used currently, please attempt reload later.");
505 SetSentErrorMessage(true);
506 return false;
509 if(*arg!='a')
510 sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
512 objmgr.LoadGameObjectScripts();
514 if(*arg!='a')
515 SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
517 return true;
520 bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
522 if(sWorld.IsScriptScheduled())
524 SendSysMessage("DB scripts used currently, please attempt reload later.");
525 SetSentErrorMessage(true);
526 return false;
529 if(*arg!='a')
530 sLog.outString( "Re-Loading Scripts from `event_scripts`...");
532 objmgr.LoadEventScripts();
534 if(*arg!='a')
535 SendGlobalSysMessage("DB table `event_scripts` reloaded.");
537 return true;
540 bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
542 if(sWorld.IsScriptScheduled())
544 SendSysMessage("DB scripts used currently, please attempt reload later.");
545 SetSentErrorMessage(true);
546 return false;
549 if(*arg!='a')
550 sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
552 objmgr.LoadQuestEndScripts();
554 if(*arg!='a')
555 SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
557 return true;
560 bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
562 if(sWorld.IsScriptScheduled())
564 SendSysMessage("DB scripts used currently, please attempt reload later.");
565 SetSentErrorMessage(true);
566 return false;
569 if(*arg!='a')
570 sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
572 objmgr.LoadQuestStartScripts();
574 if(*arg!='a')
575 SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
577 return true;
580 bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
582 if(sWorld.IsScriptScheduled())
584 SendSysMessage("DB scripts used currently, please attempt reload later.");
585 SetSentErrorMessage(true);
586 return false;
589 if(*arg!='a')
590 sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
592 objmgr.LoadSpellScripts();
594 if(*arg!='a')
595 SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
597 return true;
600 bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
602 sLog.outString( "Re-Loading Graveyard-zone links...");
604 objmgr.LoadGraveyardZones();
606 SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
608 return true;
611 bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
613 sLog.outString( "Re-Loading Game Tele coordinates...");
615 objmgr.LoadGameTele();
617 SendGlobalSysMessage("DB table `game_tele` reloaded.");
619 return true;
622 bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
624 sLog.outString( "Re-Loading Locales Creature ...");
625 objmgr.LoadCreatureLocales();
626 SendGlobalSysMessage("DB table `locales_creature` reloaded.");
627 return true;
630 bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
632 sLog.outString( "Re-Loading Locales Gameobject ... ");
633 objmgr.LoadGameObjectLocales();
634 SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
635 return true;
638 bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
640 sLog.outString( "Re-Loading Locales Item ... ");
641 objmgr.LoadItemLocales();
642 SendGlobalSysMessage("DB table `locales_item` reloaded.");
643 return true;
646 bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
648 sLog.outString( "Re-Loading Locales NPC Text ... ");
649 objmgr.LoadNpcTextLocales();
650 SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
651 return true;
654 bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
656 sLog.outString( "Re-Loading Locales Page Text ... ");
657 objmgr.LoadPageTextLocales();
658 SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
659 return true;
662 bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
664 sLog.outString( "Re-Loading Locales Quest ... ");
665 objmgr.LoadQuestLocales();
666 SendGlobalSysMessage("DB table `locales_quest` reloaded.");
667 return true;
670 bool ChatHandler::HandleLoadScriptsCommand(const char* args)
672 if(!LoadScriptingModule(args)) return true;
674 sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
675 return true;
678 bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
680 char* arg1 = strtok((char*)args, " ");
681 if( !arg1 )
682 return false;
684 /// must be NULL if targeted syntax and must be not nULL if not targeted
685 char* arg2 = strtok(NULL, " ");
687 std::string targetAccountName;
688 uint32 targetAccountId = 0;
689 uint32 targetSecurity = 0;
691 /// only target player different from self allowed (if targetPlayer!=NULL then not console)
692 Player* targetPlayer = getSelectedPlayer();
693 if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
695 /// wrong command syntax or unexpected targeting
696 if(arg2)
697 return false;
699 /// security level expected in arg2 after this if.
700 arg2 = arg1;
702 targetAccountId = targetPlayer->GetSession()->GetAccountId();
703 targetSecurity = targetPlayer->GetSession()->GetSecurity();
704 if(!accmgr.GetName(targetAccountId,targetAccountName))
706 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
707 SetSentErrorMessage(true);
708 return false;
711 else
713 /// wrong command syntax (second arg expected)
714 if(!arg2)
715 return false;
717 targetAccountName = arg1;
718 if(!AccountMgr::normilizeString(targetAccountName))
720 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
721 SetSentErrorMessage(true);
722 return false;
725 targetAccountId = accmgr.GetId(targetAccountName);
726 targetSecurity = accmgr.GetSecurity(targetAccountId);
729 int32 gm = (int32)atoi(arg2);
730 if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
732 SendSysMessage(LANG_BAD_VALUE);
733 SetSentErrorMessage(true);
734 return false;
737 /// m_session==NULL only for console
738 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
740 /// can set security level only for target with less security and to less security that we have
741 /// This is also reject self apply in fact
742 if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
744 SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
745 SetSentErrorMessage(true);
746 return false;
749 if(targetPlayer)
751 ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetName(), gm);
752 targetPlayer->GetSession()->SetSecurity(gm);
755 PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
756 loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
758 return true;
761 /// Set password for account
762 bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
764 if(!*args)
765 return false;
767 ///- Get the command line arguments
768 char *szAccount = strtok ((char*)args," ");
769 char *szPassword1 = strtok (NULL," ");
770 char *szPassword2 = strtok (NULL," ");
772 if (!szAccount||!szPassword1 || !szPassword2)
773 return false;
775 std::string account_name = szAccount;
776 if(!AccountMgr::normilizeString(account_name))
778 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
779 SetSentErrorMessage(true);
780 return false;
783 uint32 targetAccountId = accmgr.GetId(account_name);
784 if (!targetAccountId)
786 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
787 SetSentErrorMessage(true);
788 return false;
791 uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
793 /// m_session==NULL only for console
794 uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
796 /// can set password only for target with less security
797 /// This is also reject self apply in fact
798 if (targetSecurity >= plSecurity)
800 SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
801 SetSentErrorMessage (true);
802 return false;
805 if (strcmp(szPassword1,szPassword2))
807 SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
808 SetSentErrorMessage (true);
809 return false;
812 AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
814 switch(result)
816 case AOR_OK:
817 SendSysMessage(LANG_COMMAND_PASSWORD);
818 break;
819 case AOR_NAME_NOT_EXIST:
820 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
821 SetSentErrorMessage(true);
822 return false;
823 case AOR_PASS_TOO_LONG:
824 SendSysMessage(LANG_PASSWORD_TOO_LONG);
825 SetSentErrorMessage(true);
826 return false;
827 default:
828 SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
829 SetSentErrorMessage(true);
830 return false;
833 return true;
836 bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
838 if(sWorld.getAllowMovement())
840 sWorld.SetAllowMovement(false);
841 SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
843 else
845 sWorld.SetAllowMovement(true);
846 SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
848 return true;
851 bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
853 Player* SelectedPlayer = getSelectedPlayer();
854 if(!SelectedPlayer)
856 SendSysMessage(LANG_NO_CHAR_SELECTED);
857 SetSentErrorMessage(true);
858 return false;
861 // each skills that have max skill value dependent from level seted to current level max skill value
862 SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
863 return true;
866 bool ChatHandler::HandleSetSkillCommand(const char* args)
868 // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
869 char* skill_p = extractKeyFromLink((char*)args,"Hskill");
870 if(!skill_p)
871 return false;
873 char *level_p = strtok (NULL, " ");
875 if( !level_p)
876 return false;
878 char *max_p = strtok (NULL, " ");
880 int32 skill = atoi(skill_p);
882 if (skill <= 0)
884 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
885 SetSentErrorMessage(true);
886 return false;
889 int32 level = atol (level_p);
891 Player * target = getSelectedPlayer();
892 if(!target)
894 SendSysMessage(LANG_NO_CHAR_SELECTED);
895 SetSentErrorMessage(true);
896 return false;
899 SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
900 if(!sl)
902 PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
903 SetSentErrorMessage(true);
904 return false;
907 if(!target->GetSkillValue(skill))
909 PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
910 SetSentErrorMessage(true);
911 return false;
914 int32 max = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
916 if( level <= 0 || level > max || max <= 0 )
917 return false;
919 target->SetSkill(skill, level, max);
920 PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
922 return true;
925 bool ChatHandler::HandleUnLearnCommand(const char* args)
927 if (!*args)
928 return false;
930 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
931 uint32 min_id = extractSpellIdFromLink((char*)args);
932 if(!min_id)
933 return false;
935 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
936 char* tail = strtok(NULL,"");
938 uint32 max_id = extractSpellIdFromLink(tail);
940 if (!max_id)
942 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
943 max_id = min_id+1;
945 else
947 if (max_id < min_id)
948 std::swap(min_id,max_id);
950 max_id=max_id+1;
953 Player* target = getSelectedPlayer();
954 if(!target)
956 SendSysMessage(LANG_NO_CHAR_SELECTED);
957 SetSentErrorMessage(true);
958 return false;
961 for(uint32 spell=min_id;spell<max_id;spell++)
963 if (target->HasSpell(spell))
964 target->removeSpell(spell);
965 else
966 SendSysMessage(LANG_FORGET_SPELL);
969 return true;
972 bool ChatHandler::HandleCooldownCommand(const char* args)
974 Player* target = getSelectedPlayer();
975 if(!target)
977 SendSysMessage(LANG_PLAYER_NOT_FOUND);
978 SetSentErrorMessage(true);
979 return false;
982 if (!*args)
984 target->RemoveAllSpellCooldown();
985 PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
987 else
989 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
990 uint32 spell_id = extractSpellIdFromLink((char*)args);
991 if(!spell_id)
992 return false;
994 if(!sSpellStore.LookupEntry(spell_id))
996 PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
997 SetSentErrorMessage(true);
998 return false;
1001 WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1002 data << uint32(spell_id);
1003 data << uint64(target->GetGUID());
1004 target->GetSession()->SendPacket(&data);
1005 target->RemoveSpellCooldown(spell_id);
1006 PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetMangosString(LANG_YOU) : target->GetName());
1008 return true;
1011 bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1013 static const char *allSpellList[] =
1015 "3365",
1016 "6233",
1017 "6247",
1018 "6246",
1019 "6477",
1020 "6478",
1021 "22810",
1022 "8386",
1023 "21651",
1024 "21652",
1025 "522",
1026 "7266",
1027 "8597",
1028 "2479",
1029 "22027",
1030 "6603",
1031 "5019",
1032 "133",
1033 "168",
1034 "227",
1035 "5009",
1036 "9078",
1037 "668",
1038 "203",
1039 "20599",
1040 "20600",
1041 "81",
1042 "20597",
1043 "20598",
1044 "20864",
1045 "1459",
1046 "5504",
1047 "587",
1048 "5143",
1049 "118",
1050 "5505",
1051 "597",
1052 "604",
1053 "1449",
1054 "1460",
1055 "2855",
1056 "1008",
1057 "475",
1058 "5506",
1059 "1463",
1060 "12824",
1061 "8437",
1062 "990",
1063 "5145",
1064 "8450",
1065 "1461",
1066 "759",
1067 "8494",
1068 "8455",
1069 "8438",
1070 "6127",
1071 "8416",
1072 "6129",
1073 "8451",
1074 "8495",
1075 "8439",
1076 "3552",
1077 "8417",
1078 "10138",
1079 "12825",
1080 "10169",
1081 "10156",
1082 "10144",
1083 "10191",
1084 "10201",
1085 "10211",
1086 "10053",
1087 "10173",
1088 "10139",
1089 "10145",
1090 "10192",
1091 "10170",
1092 "10202",
1093 "10054",
1094 "10174",
1095 "10193",
1096 "12826",
1097 "2136",
1098 "143",
1099 "145",
1100 "2137",
1101 "2120",
1102 "3140",
1103 "543",
1104 "2138",
1105 "2948",
1106 "8400",
1107 "2121",
1108 "8444",
1109 "8412",
1110 "8457",
1111 "8401",
1112 "8422",
1113 "8445",
1114 "8402",
1115 "8413",
1116 "8458",
1117 "8423",
1118 "8446",
1119 "10148",
1120 "10197",
1121 "10205",
1122 "10149",
1123 "10215",
1124 "10223",
1125 "10206",
1126 "10199",
1127 "10150",
1128 "10216",
1129 "10207",
1130 "10225",
1131 "10151",
1132 "116",
1133 "205",
1134 "7300",
1135 "122",
1136 "837",
1137 "10",
1138 "7301",
1139 "7322",
1140 "6143",
1141 "120",
1142 "865",
1143 "8406",
1144 "6141",
1145 "7302",
1146 "8461",
1147 "8407",
1148 "8492",
1149 "8427",
1150 "8408",
1151 "6131",
1152 "7320",
1153 "10159",
1154 "8462",
1155 "10185",
1156 "10179",
1157 "10160",
1158 "10180",
1159 "10219",
1160 "10186",
1161 "10177",
1162 "10230",
1163 "10181",
1164 "10161",
1165 "10187",
1166 "10220",
1167 "2018",
1168 "2663",
1169 "12260",
1170 "2660",
1171 "3115",
1172 "3326",
1173 "2665",
1174 "3116",
1175 "2738",
1176 "3293",
1177 "2661",
1178 "3319",
1179 "2662",
1180 "9983",
1181 "8880",
1182 "2737",
1183 "2739",
1184 "7408",
1185 "3320",
1186 "2666",
1187 "3323",
1188 "3324",
1189 "3294",
1190 "22723",
1191 "23219",
1192 "23220",
1193 "23221",
1194 "23228",
1195 "23338",
1196 "10788",
1197 "10790",
1198 "5611",
1199 "5016",
1200 "5609",
1201 "2060",
1202 "10963",
1203 "10964",
1204 "10965",
1205 "22593",
1206 "22594",
1207 "596",
1208 "996",
1209 "499",
1210 "768",
1211 "17002",
1212 "1448",
1213 "1082",
1214 "16979",
1215 "1079",
1216 "5215",
1217 "20484",
1218 "5221",
1219 "15590",
1220 "17007",
1221 "6795",
1222 "6807",
1223 "5487",
1224 "1446",
1225 "1066",
1226 "5421",
1227 "3139",
1228 "779",
1229 "6811",
1230 "6808",
1231 "1445",
1232 "5216",
1233 "1737",
1234 "5222",
1235 "5217",
1236 "1432",
1237 "6812",
1238 "9492",
1239 "5210",
1240 "3030",
1241 "1441",
1242 "783",
1243 "6801",
1244 "20739",
1245 "8944",
1246 "9491",
1247 "22569",
1248 "5226",
1249 "6786",
1250 "1433",
1251 "8973",
1252 "1828",
1253 "9495",
1254 "9006",
1255 "6794",
1256 "8993",
1257 "5203",
1258 "16914",
1259 "6784",
1260 "9635",
1261 "22830",
1262 "20722",
1263 "9748",
1264 "6790",
1265 "9753",
1266 "9493",
1267 "9752",
1268 "9831",
1269 "9825",
1270 "9822",
1271 "5204",
1272 "5401",
1273 "22831",
1274 "6793",
1275 "9845",
1276 "17401",
1277 "9882",
1278 "9868",
1279 "20749",
1280 "9893",
1281 "9899",
1282 "9895",
1283 "9832",
1284 "9902",
1285 "9909",
1286 "22832",
1287 "9828",
1288 "9851",
1289 "9883",
1290 "9869",
1291 "17406",
1292 "17402",
1293 "9914",
1294 "20750",
1295 "9897",
1296 "9848",
1297 "3127",
1298 "107",
1299 "204",
1300 "9116",
1301 "2457",
1302 "78",
1303 "18848",
1304 "331",
1305 "403",
1306 "2098",
1307 "1752",
1308 "11278",
1309 "11288",
1310 "11284",
1311 "6461",
1312 "2344",
1313 "2345",
1314 "6463",
1315 "2346",
1316 "2352",
1317 "775",
1318 "1434",
1319 "1612",
1320 "71",
1321 "2468",
1322 "2458",
1323 "2467",
1324 "7164",
1325 "7178",
1326 "7367",
1327 "7376",
1328 "7381",
1329 "21156",
1330 "5209",
1331 "3029",
1332 "5201",
1333 "9849",
1334 "9850",
1335 "20719",
1336 "22568",
1337 "22827",
1338 "22828",
1339 "22829",
1340 "6809",
1341 "8972",
1342 "9005",
1343 "9823",
1344 "9827",
1345 "6783",
1346 "9913",
1347 "6785",
1348 "6787",
1349 "9866",
1350 "9867",
1351 "9894",
1352 "9896",
1353 "6800",
1354 "8992",
1355 "9829",
1356 "9830",
1357 "780",
1358 "769",
1359 "6749",
1360 "6750",
1361 "9755",
1362 "9754",
1363 "9908",
1364 "20745",
1365 "20742",
1366 "20747",
1367 "20748",
1368 "9746",
1369 "9745",
1370 "9880",
1371 "9881",
1372 "5391",
1373 "842",
1374 "3025",
1375 "3031",
1376 "3287",
1377 "3329",
1378 "1945",
1379 "3559",
1380 "4933",
1381 "4934",
1382 "4935",
1383 "4936",
1384 "5142",
1385 "5390",
1386 "5392",
1387 "5404",
1388 "5420",
1389 "6405",
1390 "7293",
1391 "7965",
1392 "8041",
1393 "8153",
1394 "9033",
1395 "9034",
1396 //"9036", problems with ghost state
1397 "16421",
1398 "21653",
1399 "22660",
1400 "5225",
1401 "9846",
1402 "2426",
1403 "5916",
1404 "6634",
1405 //"6718", phasing stealth, annoying for learn all case.
1406 "6719",
1407 "8822",
1408 "9591",
1409 "9590",
1410 "10032",
1411 "17746",
1412 "17747",
1413 "8203",
1414 "11392",
1415 "12495",
1416 "16380",
1417 "23452",
1418 "4079",
1419 "4996",
1420 "4997",
1421 "4998",
1422 "4999",
1423 "5000",
1424 "6348",
1425 "6349",
1426 "6481",
1427 "6482",
1428 "6483",
1429 "6484",
1430 "11362",
1431 "11410",
1432 "11409",
1433 "12510",
1434 "12509",
1435 "12885",
1436 "13142",
1437 "21463",
1438 "23460",
1439 "11421",
1440 "11416",
1441 "11418",
1442 "1851",
1443 "10059",
1444 "11423",
1445 "11417",
1446 "11422",
1447 "11419",
1448 "11424",
1449 "11420",
1450 "27",
1451 "31",
1452 "33",
1453 "34",
1454 "35",
1455 "15125",
1456 "21127",
1457 "22950",
1458 "1180",
1459 "201",
1460 "12593",
1461 "12842",
1462 "16770",
1463 "6057",
1464 "12051",
1465 "18468",
1466 "12606",
1467 "12605",
1468 "18466",
1469 "12502",
1470 "12043",
1471 "15060",
1472 "12042",
1473 "12341",
1474 "12848",
1475 "12344",
1476 "12353",
1477 "18460",
1478 "11366",
1479 "12350",
1480 "12352",
1481 "13043",
1482 "11368",
1483 "11113",
1484 "12400",
1485 "11129",
1486 "16766",
1487 "12573",
1488 "15053",
1489 "12580",
1490 "12475",
1491 "12472",
1492 "12953",
1493 "12488",
1494 "11189",
1495 "12985",
1496 "12519",
1497 "16758",
1498 "11958",
1499 "12490",
1500 "11426",
1501 "3565",
1502 "3562",
1503 "18960",
1504 "3567",
1505 "3561",
1506 "3566",
1507 "3563",
1508 "1953",
1509 "2139",
1510 "12505",
1511 "13018",
1512 "12522",
1513 "12523",
1514 "5146",
1515 "5144",
1516 "5148",
1517 "8419",
1518 "8418",
1519 "10213",
1520 "10212",
1521 "10157",
1522 "12524",
1523 "13019",
1524 "12525",
1525 "13020",
1526 "12526",
1527 "13021",
1528 "18809",
1529 "13031",
1530 "13032",
1531 "13033",
1532 "4036",
1533 "3920",
1534 "3919",
1535 "3918",
1536 "7430",
1537 "3922",
1538 "3923",
1539 "7411",
1540 "7418",
1541 "7421",
1542 "13262",
1543 "7412",
1544 "7415",
1545 "7413",
1546 "7416",
1547 "13920",
1548 "13921",
1549 "7745",
1550 "7779",
1551 "7428",
1552 "7457",
1553 "7857",
1554 "7748",
1555 "7426",
1556 "13421",
1557 "7454",
1558 "13378",
1559 "7788",
1560 "14807",
1561 "14293",
1562 "7795",
1563 "6296",
1564 "20608",
1565 "755",
1566 "444",
1567 "427",
1568 "428",
1569 "442",
1570 "447",
1571 "3578",
1572 "3581",
1573 "19027",
1574 "3580",
1575 "665",
1576 "3579",
1577 "3577",
1578 "6755",
1579 "3576",
1580 "2575",
1581 "2577",
1582 "2578",
1583 "2579",
1584 "2580",
1585 "2656",
1586 "2657",
1587 "2576",
1588 "3564",
1589 "10248",
1590 "8388",
1591 "2659",
1592 "14891",
1593 "3308",
1594 "3307",
1595 "10097",
1596 "2658",
1597 "3569",
1598 "16153",
1599 "3304",
1600 "10098",
1601 "4037",
1602 "3929",
1603 "3931",
1604 "3926",
1605 "3924",
1606 "3930",
1607 "3977",
1608 "3925",
1609 "136",
1610 "228",
1611 "5487",
1612 "43",
1613 "202",
1617 int loop = 0;
1618 while(strcmp(allSpellList[loop], "0"))
1620 uint32 spell = atol((char*)allSpellList[loop++]);
1622 if (m_session->GetPlayer()->HasSpell(spell))
1623 continue;
1625 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1626 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1628 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1629 continue;
1632 m_session->GetPlayer()->learnSpell(spell);
1635 SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1637 return true;
1640 bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1642 static const char *gmSpellList[] =
1644 "24347", // Become A Fish, No Breath Bar
1645 "35132", // Visual Boom
1646 "38488", // Attack 4000-8000 AOE
1647 "38795", // Attack 2000 AOE + Slow Down 90%
1648 "15712", // Attack 200
1649 "1852", // GM Spell Silence
1650 "31899", // Kill
1651 "31924", // Kill
1652 "29878", // Kill My Self
1653 "26644", // More Kill
1655 "28550", //Invisible 24
1656 "23452", //Invisible + Target
1660 uint16 gmSpellIter = 0;
1661 while( strcmp(gmSpellList[gmSpellIter], "0") )
1663 uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1665 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1666 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1668 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1669 continue;
1672 m_session->GetPlayer()->learnSpell(spell);
1675 SendSysMessage(LANG_LEARNING_GM_SKILLS);
1676 return true;
1679 bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1681 HandleLearnAllMySpellsCommand("");
1682 HandleLearnAllMyTalentsCommand("");
1683 return true;
1686 bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1688 ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1689 if(!clsEntry)
1690 return true;
1691 uint32 family = clsEntry->spellfamily;
1693 for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1695 SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1696 if(!spellInfo)
1697 continue;
1699 // skip wrong class/race skills
1700 if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1701 continue;
1703 // skip other spell families
1704 if( spellInfo->SpellFamilyName != family)
1705 continue;
1707 //TODO: skip triggered spells
1709 // skip spells with first rank learned as talent (and all talents then also)
1710 uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1711 if(GetTalentSpellCost(first_rank) > 0 )
1712 continue;
1714 // skip broken spells
1715 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1716 continue;
1718 m_session->GetPlayer()->learnSpell(i);
1721 SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1722 return true;
1725 static void learnAllHighRanks(Player* player, uint32 spellid)
1727 SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1728 for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1730 player->learnSpell(itr->second);
1731 learnAllHighRanks(player,itr->second);
1735 bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1737 Player* player = m_session->GetPlayer();
1738 uint32 classMask = player->getClassMask();
1740 for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1742 TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1743 if(!talentInfo)
1744 continue;
1746 TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1747 if(!talentTabInfo)
1748 continue;
1750 if( (classMask & talentTabInfo->ClassMask) == 0 )
1751 continue;
1753 // search highest talent rank
1754 uint32 spellid = 0;
1755 int rank = 4;
1756 for(; rank >= 0; --rank)
1758 if(talentInfo->RankID[rank]!=0)
1760 spellid = talentInfo->RankID[rank];
1761 break;
1765 if(!spellid) // ??? none spells in talent
1766 continue;
1768 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1769 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1770 continue;
1772 // learn highest rank of talent
1773 player->learnSpell(spellid);
1775 // and learn all non-talent spell ranks (recursive by tree)
1776 learnAllHighRanks(player,spellid);
1779 SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1780 return true;
1783 bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1785 // skipping UNIVERSAL language (0)
1786 for(int i = 1; i < LANGUAGES_COUNT; ++i)
1787 m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1789 SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1790 return true;
1793 bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1795 char* pName = strtok((char*)args, "");
1796 Player *player = NULL;
1797 if (pName)
1799 std::string name = pName;
1801 if(!normalizePlayerName(name))
1803 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1804 SetSentErrorMessage(true);
1805 return false;
1808 player = objmgr.GetPlayer(name.c_str());
1810 else
1811 player = getSelectedPlayer();
1813 if(!player)
1815 SendSysMessage(LANG_NO_CHAR_SELECTED);
1816 SetSentErrorMessage(true);
1817 return false;
1820 player->learnDefaultSpells();
1821 player->learnQuestRewardedSpells();
1823 PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1824 return true;
1827 bool ChatHandler::HandleLearnCommand(const char* args)
1829 Player* targetPlayer = getSelectedPlayer();
1831 if(!targetPlayer)
1833 SendSysMessage(LANG_PLAYER_NOT_FOUND);
1834 SetSentErrorMessage(true);
1835 return false;
1838 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1839 uint32 spell = extractSpellIdFromLink((char*)args);
1840 if(!spell || !sSpellStore.LookupEntry(spell))
1841 return false;
1843 if (targetPlayer->HasSpell(spell))
1845 if(targetPlayer == m_session->GetPlayer())
1846 SendSysMessage(LANG_YOU_KNOWN_SPELL);
1847 else
1848 PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1849 SetSentErrorMessage(true);
1850 return false;
1853 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1854 if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1856 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1857 SetSentErrorMessage(true);
1858 return false;
1861 targetPlayer->learnSpell(spell);
1863 return true;
1866 bool ChatHandler::HandleAddItemCommand(const char* args)
1868 if (!*args)
1869 return false;
1871 uint32 itemId = 0;
1873 if(args[0]=='[') // [name] manual form
1875 char* citemName = citemName = strtok((char*)args, "]");
1877 if(citemName && citemName[0])
1879 std::string itemName = citemName+1;
1880 WorldDatabase.escape_string(itemName);
1881 QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1882 if (!result)
1884 PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1885 SetSentErrorMessage(true);
1886 return false;
1888 itemId = result->Fetch()->GetUInt16();
1889 delete result;
1891 else
1892 return false;
1894 else // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1896 char* cId = extractKeyFromLink((char*)args,"Hitem");
1897 if(!cId)
1898 return false;
1899 itemId = atol(cId);
1902 char* ccount = strtok(NULL, " ");
1904 int32 count = 1;
1906 if (ccount)
1907 count = strtol(ccount, NULL, 10);
1909 if (count == 0)
1910 count = 1;
1912 Player* pl = m_session->GetPlayer();
1913 Player* plTarget = getSelectedPlayer();
1914 if(!plTarget)
1915 plTarget = pl;
1917 sLog.outDetail(GetMangosString(LANG_ADDITEM), itemId, count);
1919 ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1920 if(!pProto)
1922 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1923 SetSentErrorMessage(true);
1924 return false;
1927 //Subtract
1928 if (count < 0)
1930 plTarget->DestroyItemCount(itemId, -count, true, false);
1931 PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1932 return true;
1935 //Adding items
1936 uint32 noSpaceForCount = 0;
1938 // check space and find places
1939 ItemPosCountVec dest;
1940 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1941 if( msg != EQUIP_ERR_OK ) // convert to possible store amount
1942 count -= noSpaceForCount;
1944 if( count == 0 || dest.empty()) // can't add any
1946 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1947 SetSentErrorMessage(true);
1948 return false;
1951 Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1953 // remove binding (let GM give it to another player later)
1954 if(pl==plTarget)
1955 for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1956 if(Item* item1 = pl->GetItemByPos(itr->pos))
1957 item1->SetBinding( false );
1959 if(count > 0 && item)
1961 pl->SendNewItem(item,count,false,true);
1962 if(pl!=plTarget)
1963 plTarget->SendNewItem(item,count,true,false);
1966 if(noSpaceForCount > 0)
1967 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1969 return true;
1972 bool ChatHandler::HandleAddItemSetCommand(const char* args)
1974 if (!*args)
1975 return false;
1977 char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1978 if (!cId)
1979 return false;
1981 uint32 itemsetId = atol(cId);
1983 // prevent generation all items with itemset field value '0'
1984 if (itemsetId == 0)
1986 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
1987 SetSentErrorMessage(true);
1988 return false;
1991 Player* pl = m_session->GetPlayer();
1992 Player* plTarget = getSelectedPlayer();
1993 if(!plTarget)
1994 plTarget = pl;
1996 sLog.outDetail(GetMangosString(LANG_ADDITEMSET), itemsetId);
1998 bool found = false;
1999 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2001 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2002 if (!pProto)
2003 continue;
2005 if (pProto->ItemSet == itemsetId)
2007 found = true;
2008 ItemPosCountVec dest;
2009 uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2010 if (msg == EQUIP_ERR_OK)
2012 Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2014 // remove binding (let GM give it to another player later)
2015 if (pl==plTarget)
2016 item->SetBinding( false );
2018 pl->SendNewItem(item,1,false,true);
2019 if (pl!=plTarget)
2020 plTarget->SendNewItem(item,1,true,false);
2022 else
2024 pl->SendEquipError( msg, NULL, NULL );
2025 PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2030 if (!found)
2032 PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2034 SetSentErrorMessage(true);
2035 return false;
2038 return true;
2041 bool ChatHandler::HandleListItemCommand(const char* args)
2043 if(!*args)
2044 return false;
2046 char* cId = extractKeyFromLink((char*)args,"Hitem");
2047 if(!cId)
2048 return false;
2050 uint32 item_id = atol(cId);
2051 if(!item_id)
2053 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2054 SetSentErrorMessage(true);
2055 return false;
2058 ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2059 if(!itemProto)
2061 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2062 SetSentErrorMessage(true);
2063 return false;
2066 char* c_count = strtok(NULL, " ");
2067 int count = c_count ? atol(c_count) : 10;
2069 if(count < 0)
2070 return false;
2072 QueryResult *result;
2074 // inventory case
2075 uint32 inv_count = 0;
2076 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2077 if(result)
2079 inv_count = (*result)[0].GetUInt32();
2080 delete result;
2083 result=CharacterDatabase.PQuery(
2084 // 0 1 2 3 4 5
2085 "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2086 "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2087 "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2088 item_id,uint32(count));
2090 if(result)
2094 Field *fields = result->Fetch();
2095 uint32 item_guid = fields[0].GetUInt32();
2096 uint32 item_bag = fields[1].GetUInt32();
2097 uint32 item_slot = fields[2].GetUInt32();
2098 uint32 owner_guid = fields[3].GetUInt32();
2099 uint32 owner_acc = fields[4].GetUInt32();
2100 std::string owner_name = fields[5].GetCppString();
2102 char const* item_pos = 0;
2103 if(Player::IsEquipmentPos(item_bag,item_slot))
2104 item_pos = "[equipped]";
2105 else if(Player::IsInventoryPos(item_bag,item_slot))
2106 item_pos = "[in inventory]";
2107 else if(Player::IsBankPos(item_bag,item_slot))
2108 item_pos = "[in bank]";
2109 else
2110 item_pos = "";
2112 PSendSysMessage(LANG_ITEMLIST_SLOT,
2113 item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2114 } while (result->NextRow());
2116 int64 res_count = result->GetRowCount();
2118 delete result;
2120 if(count > res_count)
2121 count-=res_count;
2122 else if(count)
2123 count = 0;
2126 // mail case
2127 uint32 mail_count = 0;
2128 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2129 if(result)
2131 mail_count = (*result)[0].GetUInt32();
2132 delete result;
2135 if(count > 0)
2137 result=CharacterDatabase.PQuery(
2138 // 0 1 2 3 4 5 6
2139 "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2140 "FROM mail,mail_items,characters as char_s,characters as char_r "
2141 "WHERE mail_items.item_template='%u' AND char_s.guid = mail.sender AND char_r.guid = mail.receiver AND mail.id=mail_items.mail_id LIMIT %u",
2142 item_id,uint32(count));
2144 else
2145 result = NULL;
2147 if(result)
2151 Field *fields = result->Fetch();
2152 uint32 item_guid = fields[0].GetUInt32();
2153 uint32 item_s = fields[1].GetUInt32();
2154 uint32 item_r = fields[2].GetUInt32();
2155 uint32 item_s_acc = fields[3].GetUInt32();
2156 std::string item_s_name = fields[4].GetCppString();
2157 uint32 item_r_acc = fields[5].GetUInt32();
2158 std::string item_r_name = fields[6].GetCppString();
2160 char const* item_pos = "[in mail]";
2162 PSendSysMessage(LANG_ITEMLIST_MAIL,
2163 item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2164 } while (result->NextRow());
2166 int64 res_count = result->GetRowCount();
2168 delete result;
2170 if(count > res_count)
2171 count-=res_count;
2172 else if(count)
2173 count = 0;
2176 // auction case
2177 uint32 auc_count = 0;
2178 result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2179 if(result)
2181 auc_count = (*result)[0].GetUInt32();
2182 delete result;
2185 if(count > 0)
2187 result=CharacterDatabase.PQuery(
2188 // 0 1 2 3
2189 "SELECT auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2190 "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2191 item_id,uint32(count));
2193 else
2194 result = NULL;
2196 if(result)
2200 Field *fields = result->Fetch();
2201 uint32 item_guid = fields[0].GetUInt32();
2202 uint32 owner = fields[1].GetUInt32();
2203 uint32 owner_acc = fields[2].GetUInt32();
2204 std::string owner_name = fields[3].GetCppString();
2206 char const* item_pos = "[in auction]";
2208 PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2209 } while (result->NextRow());
2211 delete result;
2214 // guild bank case
2215 uint32 guild_count = 0;
2216 result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2217 if(result)
2219 guild_count = (*result)[0].GetUInt32();
2220 delete result;
2223 result=CharacterDatabase.PQuery(
2224 // 0 1 2
2225 "SELECT gi.item_guid, gi.guildid, guild.name "
2226 "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2227 item_id,uint32(count));
2229 if(result)
2233 Field *fields = result->Fetch();
2234 uint32 item_guid = fields[0].GetUInt32();
2235 uint32 guild_guid = fields[1].GetUInt32();
2236 std::string guild_name = fields[2].GetCppString();
2238 char const* item_pos = "[in guild bank]";
2240 PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2241 } while (result->NextRow());
2243 int64 res_count = result->GetRowCount();
2245 delete result;
2247 if(count > res_count)
2248 count-=res_count;
2249 else if(count)
2250 count = 0;
2253 if(inv_count+mail_count+auc_count+guild_count == 0)
2255 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2256 SetSentErrorMessage(true);
2257 return false;
2260 PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2262 return true;
2265 bool ChatHandler::HandleListObjectCommand(const char* args)
2267 if(!*args)
2268 return false;
2270 // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2271 char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2272 if(!cId)
2273 return false;
2275 uint32 go_id = atol(cId);
2276 if(!go_id)
2278 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2279 SetSentErrorMessage(true);
2280 return false;
2283 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2284 if(!gInfo)
2286 PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2287 SetSentErrorMessage(true);
2288 return false;
2291 char* c_count = strtok(NULL, " ");
2292 int count = c_count ? atol(c_count) : 10;
2294 if(count < 0)
2295 return false;
2297 QueryResult *result;
2299 uint32 obj_count = 0;
2300 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2301 if(result)
2303 obj_count = (*result)[0].GetUInt32();
2304 delete result;
2307 if(m_session)
2309 Player* pl = m_session->GetPlayer();
2310 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM gameobject WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2311 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2313 else
2314 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2315 go_id,uint32(count));
2317 if (result)
2321 Field *fields = result->Fetch();
2322 uint32 guid = fields[0].GetUInt32();
2323 float x = fields[1].GetFloat();
2324 float y = fields[2].GetFloat();
2325 float z = fields[3].GetFloat();
2326 int mapid = fields[4].GetUInt16();
2328 if (m_session)
2329 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2330 else
2331 PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2332 } while (result->NextRow());
2334 delete result;
2337 PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2338 return true;
2341 bool ChatHandler::HandleNearObjectCommand(const char* args)
2343 float distance = (!*args) ? 10 : atol(args);
2344 uint32 count = 0;
2346 Player* pl = m_session->GetPlayer();
2347 QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2348 "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2349 "FROM gameobject WHERE map='%u' AND (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) <= '%f' ORDER BY order_",
2350 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2351 pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2353 if (result)
2357 Field *fields = result->Fetch();
2358 uint32 guid = fields[0].GetUInt32();
2359 uint32 entry = fields[1].GetUInt32();
2360 float x = fields[2].GetFloat();
2361 float y = fields[3].GetFloat();
2362 float z = fields[4].GetFloat();
2363 int mapid = fields[5].GetUInt16();
2365 GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2367 if(!gInfo)
2368 continue;
2370 PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2372 ++count;
2373 } while (result->NextRow());
2375 delete result;
2378 PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2379 return true;
2382 bool ChatHandler::HandleListCreatureCommand(const char* args)
2384 if(!*args)
2385 return false;
2387 // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2388 char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2389 if(!cId)
2390 return false;
2392 uint32 cr_id = atol(cId);
2393 if(!cr_id)
2395 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2396 SetSentErrorMessage(true);
2397 return false;
2400 CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2401 if(!cInfo)
2403 PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2404 SetSentErrorMessage(true);
2405 return false;
2408 char* c_count = strtok(NULL, " ");
2409 int count = c_count ? atol(c_count) : 10;
2411 if(count < 0)
2412 return false;
2414 QueryResult *result;
2416 uint32 cr_count = 0;
2417 result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2418 if(result)
2420 cr_count = (*result)[0].GetUInt32();
2421 delete result;
2424 if(m_session)
2426 Player* pl = m_session->GetPlayer();
2427 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map, (POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ FROM creature WHERE id = '%u' ORDER BY order_ ASC LIMIT %u",
2428 pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2430 else
2431 result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2432 cr_id,uint32(count));
2434 if (result)
2438 Field *fields = result->Fetch();
2439 uint32 guid = fields[0].GetUInt32();
2440 float x = fields[1].GetFloat();
2441 float y = fields[2].GetFloat();
2442 float z = fields[3].GetFloat();
2443 int mapid = fields[4].GetUInt16();
2445 if (m_session)
2446 PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2447 else
2448 PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2449 } while (result->NextRow());
2451 delete result;
2454 PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2455 return true;
2458 bool ChatHandler::HandleLookupItemCommand(const char* args)
2460 if(!*args)
2461 return false;
2463 std::string namepart = args;
2464 std::wstring wnamepart;
2466 // converting string that we try to find to lower case
2467 if(!Utf8toWStr(namepart,wnamepart))
2468 return false;
2470 wstrToLower(wnamepart);
2472 uint32 counter = 0;
2474 // Search in `item_template`
2475 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2477 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2478 if(!pProto)
2479 continue;
2481 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2482 if ( loc_idx >= 0 )
2484 ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2485 if (il)
2487 if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2489 std::string name = il->Name[loc_idx];
2491 if (Utf8FitTo(name, wnamepart))
2493 if (m_session)
2494 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2495 else
2496 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2497 ++counter;
2498 continue;
2504 std::string name = pProto->Name1;
2505 if(name.empty())
2506 continue;
2508 if (Utf8FitTo(name, wnamepart))
2510 if (m_session)
2511 PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2512 else
2513 PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2514 ++counter;
2518 if (counter==0)
2519 SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2521 return true;
2524 bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2526 if(!*args)
2527 return false;
2529 std::string namepart = args;
2530 std::wstring wnamepart;
2532 if(!Utf8toWStr(namepart,wnamepart))
2533 return false;
2535 // converting string that we try to find to lower case
2536 wstrToLower( wnamepart );
2538 uint32 counter = 0; // Counter for figure out that we found smth.
2540 // Search in ItemSet.dbc
2541 for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2543 ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2544 if(set)
2546 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2547 std::string name = set->name[loc];
2548 if(name.empty())
2549 continue;
2551 if (!Utf8FitTo(name, wnamepart))
2553 loc = 0;
2554 for(; loc < MAX_LOCALE; ++loc)
2556 if(m_session && loc==m_session->GetSessionDbcLocale())
2557 continue;
2559 name = set->name[loc];
2560 if(name.empty())
2561 continue;
2563 if (Utf8FitTo(name, wnamepart))
2564 break;
2568 if(loc < MAX_LOCALE)
2570 // send item set in "id - [namedlink locale]" format
2571 if (m_session)
2572 PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2573 else
2574 PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2575 ++counter;
2579 if (counter == 0) // if counter == 0 then we found nth
2580 SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2581 return true;
2584 bool ChatHandler::HandleLookupSkillCommand(const char* args)
2586 if(!*args)
2587 return false;
2589 // can be NULL in console call
2590 Player* target = getSelectedPlayer();
2592 std::string namepart = args;
2593 std::wstring wnamepart;
2595 if(!Utf8toWStr(namepart,wnamepart))
2596 return false;
2598 // converting string that we try to find to lower case
2599 wstrToLower( wnamepart );
2601 uint32 counter = 0; // Counter for figure out that we found smth.
2603 // Search in SkillLine.dbc
2604 for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2606 SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2607 if(skillInfo)
2609 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2610 std::string name = skillInfo->name[loc];
2611 if(name.empty())
2612 continue;
2614 if (!Utf8FitTo(name, wnamepart))
2616 loc = 0;
2617 for(; loc < MAX_LOCALE; ++loc)
2619 if(m_session && loc==m_session->GetSessionDbcLocale())
2620 continue;
2622 name = skillInfo->name[loc];
2623 if(name.empty())
2624 continue;
2626 if (Utf8FitTo(name, wnamepart))
2627 break;
2631 if(loc < MAX_LOCALE)
2633 char const* knownStr = "";
2634 if(target && target->HasSkill(id))
2635 knownStr = GetMangosString(LANG_KNOWN);
2637 // send skill in "id - [namedlink locale]" format
2638 if (m_session)
2639 PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2640 else
2641 PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2643 ++counter;
2647 if (counter == 0) // if counter == 0 then we found nth
2648 SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2649 return true;
2652 bool ChatHandler::HandleLookupSpellCommand(const char* args)
2654 if(!*args)
2655 return false;
2657 // can be NULL at console call
2658 Player* target = getSelectedPlayer();
2660 std::string namepart = args;
2661 std::wstring wnamepart;
2663 if(!Utf8toWStr(namepart,wnamepart))
2664 return false;
2666 // converting string that we try to find to lower case
2667 wstrToLower( wnamepart );
2669 uint32 counter = 0; // Counter for figure out that we found smth.
2671 // Search in Spell.dbc
2672 for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2674 SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2675 if(spellInfo)
2677 int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2678 std::string name = spellInfo->SpellName[loc];
2679 if(name.empty())
2680 continue;
2682 if (!Utf8FitTo(name, wnamepart))
2684 loc = 0;
2685 for(; loc < MAX_LOCALE; ++loc)
2687 if(m_session && loc==m_session->GetSessionDbcLocale())
2688 continue;
2690 name = spellInfo->SpellName[loc];
2691 if(name.empty())
2692 continue;
2694 if (Utf8FitTo(name, wnamepart))
2695 break;
2699 if(loc < MAX_LOCALE)
2701 bool known = target && target->HasSpell(id);
2702 bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2704 uint32 talentCost = GetTalentSpellCost(id);
2706 bool talent = (talentCost > 0);
2707 bool passive = IsPassiveSpell(id);
2708 bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
2710 // unit32 used to prevent interpreting uint8 as char at output
2711 // find rank of learned spell for learning spell, or talent rank
2712 uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2714 // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2715 std::ostringstream ss;
2716 if (m_session)
2717 ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2718 else
2719 ss << id << " - " << name;
2721 // include rank in link name
2722 if(rank)
2723 ss << GetMangosString(LANG_SPELL_RANK) << rank;
2725 if (m_session)
2726 ss << " " << localeNames[loc] << "]|h|r";
2727 else
2728 ss << " " << localeNames[loc];
2730 if(talent)
2731 ss << GetMangosString(LANG_TALENT);
2732 if(passive)
2733 ss << GetMangosString(LANG_PASSIVE);
2734 if(learn)
2735 ss << GetMangosString(LANG_LEARN);
2736 if(known)
2737 ss << GetMangosString(LANG_KNOWN);
2738 if(active)
2739 ss << GetMangosString(LANG_ACTIVE);
2741 SendSysMessage(ss.str().c_str());
2743 ++counter;
2747 if (counter == 0) // if counter == 0 then we found nth
2748 SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2749 return true;
2752 bool ChatHandler::HandleLookupQuestCommand(const char* args)
2754 if(!*args)
2755 return false;
2757 // can be NULL at console call
2758 Player* target = getSelectedPlayer();
2760 std::string namepart = args;
2761 std::wstring wnamepart;
2763 // converting string that we try to find to lower case
2764 if(!Utf8toWStr(namepart,wnamepart))
2765 return false;
2767 wstrToLower(wnamepart);
2769 uint32 counter = 0 ;
2771 ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2772 for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2774 Quest * qinfo = iter->second;
2776 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2777 if ( loc_idx >= 0 )
2779 QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2780 if (il)
2782 if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2784 std::string title = il->Title[loc_idx];
2786 if (Utf8FitTo(title, wnamepart))
2788 char const* statusStr = "";
2790 if(target)
2792 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2794 if(status == QUEST_STATUS_COMPLETE)
2796 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2797 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2798 else
2799 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2801 else if(status == QUEST_STATUS_INCOMPLETE)
2802 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2805 if (m_session)
2806 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2807 else
2808 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2809 ++counter;
2810 continue;
2816 std::string title = qinfo->GetTitle();
2817 if(title.empty())
2818 continue;
2820 if (Utf8FitTo(title, wnamepart))
2822 char const* statusStr = "";
2824 if(target)
2826 QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2828 if(status == QUEST_STATUS_COMPLETE)
2830 if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2831 statusStr = GetMangosString(LANG_COMMAND_QUEST_REWARDED);
2832 else
2833 statusStr = GetMangosString(LANG_COMMAND_QUEST_COMPLETE);
2835 else if(status == QUEST_STATUS_INCOMPLETE)
2836 statusStr = GetMangosString(LANG_COMMAND_QUEST_ACTIVE);
2839 if (m_session)
2840 PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2841 else
2842 PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2844 ++counter;
2848 if (counter==0)
2849 SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2851 return true;
2854 bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2856 if (!*args)
2857 return false;
2859 std::string namepart = args;
2860 std::wstring wnamepart;
2862 // converting string that we try to find to lower case
2863 if (!Utf8toWStr (namepart,wnamepart))
2864 return false;
2866 wstrToLower (wnamepart);
2868 uint32 counter = 0;
2870 for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2872 CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2873 if(!cInfo)
2874 continue;
2876 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2877 if (loc_idx >= 0)
2879 CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2880 if (cl)
2882 if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2884 std::string name = cl->Name[loc_idx];
2886 if (Utf8FitTo (name, wnamepart))
2888 if (m_session)
2889 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2890 else
2891 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2892 ++counter;
2893 continue;
2899 std::string name = cInfo->Name;
2900 if (name.empty ())
2901 continue;
2903 if (Utf8FitTo(name, wnamepart))
2905 if (m_session)
2906 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2907 else
2908 PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2909 ++counter;
2913 if (counter==0)
2914 SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2916 return true;
2919 bool ChatHandler::HandleLookupObjectCommand(const char* args)
2921 if(!*args)
2922 return false;
2924 std::string namepart = args;
2925 std::wstring wnamepart;
2927 // converting string that we try to find to lower case
2928 if(!Utf8toWStr(namepart,wnamepart))
2929 return false;
2931 wstrToLower(wnamepart);
2933 uint32 counter = 0;
2935 for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2937 GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2938 if(!gInfo)
2939 continue;
2941 int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2942 if ( loc_idx >= 0 )
2944 GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2945 if (gl)
2947 if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
2949 std::string name = gl->Name[loc_idx];
2951 if (Utf8FitTo(name, wnamepart))
2953 if (m_session)
2954 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2955 else
2956 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2957 ++counter;
2958 continue;
2964 std::string name = gInfo->name;
2965 if(name.empty())
2966 continue;
2968 if(Utf8FitTo(name, wnamepart))
2970 if (m_session)
2971 PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
2972 else
2973 PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
2974 ++counter;
2978 if(counter==0)
2979 SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
2981 return true;
2984 /** \brief GM command level 3 - Create a guild.
2986 * This command allows a GM (level 3) to create a guild.
2988 * The "args" parameter contains the name of the guild leader
2989 * and then the name of the guild.
2992 bool ChatHandler::HandleGuildCreateCommand(const char* args)
2995 if (!*args)
2996 return false;
2998 char *lname = strtok ((char*)args, " ");
2999 char *gname = strtok (NULL, "");
3001 if (!lname)
3002 return false;
3004 if (!gname)
3006 SendSysMessage (LANG_INSERT_GUILD_NAME);
3007 SetSentErrorMessage (true);
3008 return false;
3011 std::string guildname = gname;
3013 Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3014 if (!player)
3016 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3017 SetSentErrorMessage (true);
3018 return false;
3021 if (player->GetGuildId())
3023 SendSysMessage (LANG_PLAYER_IN_GUILD);
3024 return true;
3027 Guild *guild = new Guild;
3028 if (!guild->create (player->GetGUID (),guildname))
3030 delete guild;
3031 SendSysMessage (LANG_GUILD_NOT_CREATED);
3032 SetSentErrorMessage (true);
3033 return false;
3036 objmgr.AddGuild (guild);
3037 return true;
3040 bool ChatHandler::HandleGuildInviteCommand(const char *args)
3042 if (!*args)
3043 return false;
3045 char* par1 = strtok ((char*)args, " ");
3046 char* par2 = strtok (NULL, "");
3047 if(!par1 || !par2)
3048 return false;
3050 std::string glName = par2;
3051 Guild* targetGuild = objmgr.GetGuildByName (glName);
3052 if (!targetGuild)
3053 return false;
3055 std::string plName = par1;
3056 if (!normalizePlayerName (plName))
3058 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3059 SetSentErrorMessage (true);
3060 return false;
3063 uint64 plGuid = 0;
3064 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3065 plGuid = targetPlayer->GetGUID ();
3066 else
3067 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3069 if (!plGuid)
3070 false;
3072 // player's guild membership checked in AddMember before add
3073 if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3074 return false;
3076 return true;
3079 bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3081 if (!*args)
3082 return false;
3084 char* par1 = strtok ((char*)args, " ");
3085 if(!par1)
3086 return false;
3088 std::string plName = par1;
3089 if (!normalizePlayerName (plName))
3091 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3092 SetSentErrorMessage (true);
3093 return false;
3096 uint64 plGuid = 0;
3097 uint32 glId = 0;
3098 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3100 plGuid = targetPlayer->GetGUID ();
3101 glId = targetPlayer->GetGuildId ();
3103 else
3105 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3106 glId = Player::GetGuildIdFromDB (plGuid);
3109 if (!plGuid || !glId)
3110 return false;
3112 Guild* targetGuild = objmgr.GetGuildById (glId);
3113 if (!targetGuild)
3114 return false;
3116 targetGuild->DelMember (plGuid);
3118 return true;
3121 bool ChatHandler::HandleGuildRankCommand(const char *args)
3123 if (!*args)
3124 return false;
3126 char* par1 = strtok ((char*)args, " ");
3127 char* par2 = strtok (NULL, " ");
3128 if (!par1 || !par2)
3129 return false;
3130 std::string plName = par1;
3131 if (!normalizePlayerName (plName))
3133 SendSysMessage (LANG_PLAYER_NOT_FOUND);
3134 SetSentErrorMessage (true);
3135 return false;
3138 uint64 plGuid = 0;
3139 uint32 glId = 0;
3140 if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3142 plGuid = targetPlayer->GetGUID ();
3143 glId = targetPlayer->GetGuildId ();
3145 else
3147 plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3148 glId = Player::GetGuildIdFromDB (plGuid);
3151 if (!plGuid || !glId)
3152 return false;
3154 Guild* targetGuild = objmgr.GetGuildById (glId);
3155 if (!targetGuild)
3156 return false;
3158 uint32 newrank = uint32 (atoi (par2));
3159 if (newrank > targetGuild->GetLowestRank ())
3160 return false;
3162 targetGuild->ChangeRank (plGuid,newrank);
3164 return true;
3167 bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3169 if (!*args)
3170 return false;
3172 char* par1 = strtok ((char*)args, " ");
3173 if (!par1)
3174 return false;
3176 std::string gld = par1;
3178 Guild* targetGuild = objmgr.GetGuildByName (gld);
3179 if (!targetGuild)
3180 return false;
3182 targetGuild->Disband ();
3184 return true;
3187 bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3189 Unit* pUnit = getSelectedUnit();
3191 if(!pUnit)
3193 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3194 SetSentErrorMessage(true);
3195 return false;
3198 PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3200 return true;
3203 // FIX-ME!!!
3205 bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3207 /*if (!*args)
3208 return false;
3210 uint64 guid = m_session->GetPlayer()->GetSelection();
3211 if (guid == 0)
3213 SendSysMessage(LANG_NO_SELECTION);
3214 return true;
3217 Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3219 if(!pCreature)
3221 SendSysMessage(LANG_SELECT_CREATURE);
3222 return true;
3225 char* pSlotID = strtok((char*)args, " ");
3226 if (!pSlotID)
3227 return false;
3229 char* pItemID = strtok(NULL, " ");
3230 if (!pItemID)
3231 return false;
3233 uint32 ItemID = atoi(pItemID);
3234 uint32 SlotID = atoi(pSlotID);
3236 ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3238 bool added = false;
3239 if(tmpItem)
3241 switch(SlotID)
3243 case 1:
3244 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3245 added = true;
3246 break;
3247 case 2:
3248 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3249 added = true;
3250 break;
3251 case 3:
3252 pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3253 added = true;
3254 break;
3255 default:
3256 PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3257 added = false;
3258 break;
3260 if(added)
3262 PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3265 else
3267 PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3268 return true;
3271 return true;
3274 bool ChatHandler::HandleDieCommand(const char* /*args*/)
3276 Unit* target = getSelectedUnit();
3278 if(!target || !m_session->GetPlayer()->GetSelection())
3280 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3281 SetSentErrorMessage(true);
3282 return false;
3285 if( target->isAlive() )
3287 m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3290 return true;
3293 bool ChatHandler::HandleDamageCommand(const char * args)
3295 if (!*args)
3296 return false;
3298 Unit* target = getSelectedUnit();
3300 if(!target || !m_session->GetPlayer()->GetSelection())
3302 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3303 SetSentErrorMessage(true);
3304 return false;
3307 if( !target->isAlive() )
3308 return true;
3310 char* damageStr = strtok((char*)args, " ");
3311 if(!damageStr)
3312 return false;
3314 int32 damage = atoi((char*)damageStr);
3315 if(damage <=0)
3316 return true;
3318 char* schoolStr = strtok((char*)NULL, " ");
3320 // flat melee damage without resistence/etc reduction
3321 if(!schoolStr)
3323 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3324 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3325 return true;
3328 uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3329 if(school >= MAX_SPELL_SCHOOL)
3330 return false;
3332 SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3334 if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3335 damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3337 char* spellStr = strtok((char*)NULL, " ");
3339 // melee damage by specific school
3340 if(!spellStr)
3342 uint32 absorb = 0;
3343 uint32 resist = 0;
3345 m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3347 if (damage <= absorb + resist)
3348 return true;
3350 damage -= absorb + resist;
3352 m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3353 m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3354 return true;
3357 // non-melee damage
3359 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3360 uint32 spellid = extractSpellIdFromLink((char*)args);
3361 if(!spellid || !sSpellStore.LookupEntry(spellid))
3362 return false;
3364 m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3365 return true;
3368 bool ChatHandler::HandleModifyArenaCommand(const char * args)
3370 if (!*args)
3371 return false;
3373 Player *target = getSelectedPlayer();
3374 if(!target)
3376 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3377 SetSentErrorMessage(true);
3378 return false;
3381 int32 amount = (uint32)atoi(args);
3383 target->ModifyArenaPoints(amount);
3385 PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3387 return true;
3390 bool ChatHandler::HandleReviveCommand(const char* args)
3392 Player* SelectedPlayer = NULL;
3394 if (*args)
3396 std::string name = args;
3397 if(!normalizePlayerName(name))
3399 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3400 SetSentErrorMessage(true);
3401 return false;
3404 SelectedPlayer = objmgr.GetPlayer(name.c_str());
3406 else
3407 SelectedPlayer = getSelectedPlayer();
3409 if(!SelectedPlayer)
3411 SendSysMessage(LANG_NO_CHAR_SELECTED);
3412 SetSentErrorMessage(true);
3413 return false;
3416 SelectedPlayer->ResurrectPlayer(0.5f);
3417 SelectedPlayer->SpawnCorpseBones();
3418 SelectedPlayer->SaveToDB();
3419 return true;
3422 bool ChatHandler::HandleAuraCommand(const char* args)
3424 char* px = strtok((char*)args, " ");
3425 if (!px)
3426 return false;
3428 Unit *target = getSelectedUnit();
3429 if(!target)
3431 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3432 SetSentErrorMessage(true);
3433 return false;
3436 uint32 spellID = (uint32)atoi(px);
3437 SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3438 if(spellInfo)
3440 for(uint32 i = 0;i<3;i++)
3442 uint8 eff = spellInfo->Effect[i];
3443 if (eff>=TOTAL_SPELL_EFFECTS)
3444 continue;
3445 if( IsAreaAuraEffect(eff) ||
3446 eff == SPELL_EFFECT_APPLY_AURA ||
3447 eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3449 Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3450 target->AddAura(Aur);
3455 return true;
3458 bool ChatHandler::HandleUnAuraCommand(const char* args)
3460 char* px = strtok((char*)args, " ");
3461 if (!px)
3462 return false;
3464 Unit *target = getSelectedUnit();
3465 if(!target)
3467 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3468 SetSentErrorMessage(true);
3469 return false;
3472 std::string argstr = args;
3473 if (argstr == "all")
3475 target->RemoveAllAuras();
3476 return true;
3479 uint32 spellID = (uint32)atoi(px);
3480 target->RemoveAurasDueToSpell(spellID);
3482 return true;
3485 bool ChatHandler::HandleLinkGraveCommand(const char* args)
3487 if(!*args)
3488 return false;
3490 char* px = strtok((char*)args, " ");
3491 if (!px)
3492 return false;
3494 uint32 g_id = (uint32)atoi(px);
3496 uint32 g_team;
3498 char* px2 = strtok(NULL, " ");
3500 if (!px2)
3501 g_team = 0;
3502 else if (strncmp(px2,"horde",6)==0)
3503 g_team = HORDE;
3504 else if (strncmp(px2,"alliance",9)==0)
3505 g_team = ALLIANCE;
3506 else
3507 return false;
3509 WorldSafeLocsEntry const* graveyard = sWorldSafeLocsStore.LookupEntry(g_id);
3511 if(!graveyard )
3513 PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3514 SetSentErrorMessage(true);
3515 return false;
3518 Player* player = m_session->GetPlayer();
3520 uint32 zoneId = player->GetZoneId();
3522 AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3523 if(!areaEntry || areaEntry->zone !=0 )
3525 PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3526 SetSentErrorMessage(true);
3527 return false;
3530 if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3532 SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3533 SetSentErrorMessage(true);
3534 return false;
3537 if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3538 PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3539 else
3540 PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3542 return true;
3545 bool ChatHandler::HandleNearGraveCommand(const char* args)
3547 uint32 g_team;
3549 size_t argslen = strlen(args);
3551 if(!*args)
3552 g_team = 0;
3553 else if (strncmp((char*)args,"horde",argslen)==0)
3554 g_team = HORDE;
3555 else if (strncmp((char*)args,"alliance",argslen)==0)
3556 g_team = ALLIANCE;
3557 else
3558 return false;
3560 Player* player = m_session->GetPlayer();
3562 WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3563 player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3565 if(graveyard)
3567 uint32 g_id = graveyard->ID;
3569 GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3570 if (!data)
3572 PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3573 SetSentErrorMessage(true);
3574 return false;
3577 g_team = data->team;
3579 std::string team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3581 if(g_team == 0)
3582 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3583 else if(g_team == HORDE)
3584 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3585 else if(g_team == ALLIANCE)
3586 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3588 PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3590 else
3592 std::string team_name;
3594 if(g_team == 0)
3595 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ANY);
3596 else if(g_team == HORDE)
3597 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_HORDE);
3598 else if(g_team == ALLIANCE)
3599 team_name = GetMangosString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3601 if(g_team == ~uint32(0))
3602 PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3603 else
3604 PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3607 return true;
3610 //play npc emote
3611 bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3613 uint32 emote = atoi((char*)args);
3615 Creature* target = getSelectedCreature();
3616 if(!target)
3618 SendSysMessage(LANG_SELECT_CREATURE);
3619 SetSentErrorMessage(true);
3620 return false;
3623 target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3625 return true;
3628 bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3630 Creature* target = getSelectedCreature();
3632 if(!target)
3634 SendSysMessage(LANG_SELECT_CREATURE);
3635 SetSentErrorMessage(true);
3636 return false;
3639 uint32 faction = target->getFaction();
3640 uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3641 uint32 displayid = target->GetDisplayId();
3642 uint32 nativeid = target->GetNativeDisplayId();
3643 uint32 Entry = target->GetEntry();
3644 CreatureInfo const* cInfo = target->GetCreatureInfo();
3646 int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3647 if(curRespawnDelay < 0)
3648 curRespawnDelay = 0;
3649 std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3650 std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3652 PSendSysMessage(LANG_NPCINFO_CHAR, target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3653 PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3654 PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3655 PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3656 PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3657 PSendSysMessage(LANG_NPCINFO_LOOT, cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3658 PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3659 PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3661 if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3663 SendSysMessage(LANG_NPCINFO_VENDOR);
3665 if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3667 SendSysMessage(LANG_NPCINFO_TRAINER);
3670 return true;
3673 bool ChatHandler::HandleExploreCheatCommand(const char* args)
3675 if (!*args)
3676 return false;
3678 int flag = atoi((char*)args);
3680 Player *chr = getSelectedPlayer();
3681 if (chr == NULL)
3683 SendSysMessage(LANG_NO_CHAR_SELECTED);
3684 SetSentErrorMessage(true);
3685 return false;
3688 if (flag != 0)
3690 PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3691 if (needReportToTarget(chr))
3692 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetName());
3694 else
3696 PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3697 if (needReportToTarget(chr))
3698 ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetName());
3701 for (uint8 i=0; i<128; i++)
3703 if (flag != 0)
3705 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3707 else
3709 m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3713 return true;
3716 bool ChatHandler::HandleHoverCommand(const char* args)
3718 char* px = strtok((char*)args, " ");
3719 uint32 flag;
3720 if (!px)
3721 flag = 1;
3722 else
3723 flag = atoi(px);
3725 m_session->GetPlayer()->SetHover(flag);
3727 if (flag)
3728 SendSysMessage(LANG_HOVER_ENABLED);
3729 else
3730 SendSysMessage(LANG_HOVER_DISABLED);
3732 return true;
3735 bool ChatHandler::HandleLevelUpCommand(const char* args)
3737 char* px = strtok((char*)args, " ");
3738 char* py = strtok((char*)NULL, " ");
3740 // command format parsing
3741 char* pname = (char*)NULL;
3742 int addlevel = 1;
3744 if(px && py) // .levelup name level
3746 addlevel = atoi(py);
3747 pname = px;
3749 else if(px && !py) // .levelup name OR .levelup level
3751 if(isalpha(px[0])) // .levelup name
3752 pname = px;
3753 else // .levelup level
3754 addlevel = atoi(px);
3756 // else .levelup - nothing do for preparing
3758 // player
3759 Player *chr = NULL;
3760 uint64 chr_guid = 0;
3762 std::string name;
3764 if(pname) // player by name
3766 name = pname;
3767 if(!normalizePlayerName(name))
3769 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3770 SetSentErrorMessage(true);
3771 return false;
3774 chr = objmgr.GetPlayer(name.c_str());
3775 if(!chr) // not in game
3777 chr_guid = objmgr.GetPlayerGUIDByName(name);
3778 if (chr_guid == 0)
3780 SendSysMessage(LANG_PLAYER_NOT_FOUND);
3781 SetSentErrorMessage(true);
3782 return false;
3786 else // player by selection
3788 chr = getSelectedPlayer();
3790 if (chr == NULL)
3792 SendSysMessage(LANG_NO_CHAR_SELECTED);
3793 SetSentErrorMessage(true);
3794 return false;
3797 name = chr->GetName();
3800 assert(chr || chr_guid);
3802 int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3803 int32 newlevel = oldlevel + addlevel;
3804 if(newlevel < 1)
3805 newlevel = 1;
3806 if(newlevel > 255) // hardcoded maximum level
3807 newlevel = 255;
3809 if(chr)
3811 chr->GiveLevel(newlevel);
3812 chr->InitTalentForLevel();
3813 chr->SetUInt32Value(PLAYER_XP,0);
3815 if(oldlevel == newlevel)
3816 ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3817 else
3818 if(oldlevel < newlevel)
3819 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3820 else
3821 if(oldlevel > newlevel)
3822 ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3824 else
3826 // update level and XP at level, all other will be updated at loading
3827 Tokens values;
3828 Player::LoadValuesArrayFromDB(values,chr_guid);
3829 Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3830 Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3831 Player::SaveValuesArrayInDB(values,chr_guid);
3834 if(m_session->GetPlayer() != chr) // including chr==NULL
3835 PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3836 return true;
3839 bool ChatHandler::HandleShowAreaCommand(const char* args)
3841 if (!*args)
3842 return false;
3844 int area = atoi((char*)args);
3846 Player *chr = getSelectedPlayer();
3847 if (chr == NULL)
3849 SendSysMessage(LANG_NO_CHAR_SELECTED);
3850 SetSentErrorMessage(true);
3851 return false;
3854 int offset = area / 32;
3855 uint32 val = (uint32)(1 << (area % 32));
3857 if(offset >= 128)
3859 SendSysMessage(LANG_BAD_VALUE);
3860 SetSentErrorMessage(true);
3861 return false;
3864 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3865 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3867 SendSysMessage(LANG_EXPLORE_AREA);
3868 return true;
3871 bool ChatHandler::HandleHideAreaCommand(const char* args)
3873 if (!*args)
3874 return false;
3876 int area = atoi((char*)args);
3878 Player *chr = getSelectedPlayer();
3879 if (chr == NULL)
3881 SendSysMessage(LANG_NO_CHAR_SELECTED);
3882 SetSentErrorMessage(true);
3883 return false;
3886 int offset = area / 32;
3887 uint32 val = (uint32)(1 << (area % 32));
3889 if(offset >= 128)
3891 SendSysMessage(LANG_BAD_VALUE);
3892 SetSentErrorMessage(true);
3893 return false;
3896 uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3897 chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3899 SendSysMessage(LANG_UNEXPLORE_AREA);
3900 return true;
3903 bool ChatHandler::HandleUpdate(const char* args)
3905 if(!*args)
3906 return false;
3908 uint32 updateIndex;
3909 uint32 value;
3911 char* pUpdateIndex = strtok((char*)args, " ");
3913 Unit* chr = getSelectedUnit();
3914 if (chr == NULL)
3916 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3917 SetSentErrorMessage(true);
3918 return false;
3921 if(!pUpdateIndex)
3923 return true;
3925 updateIndex = atoi(pUpdateIndex);
3926 //check updateIndex
3927 if(chr->GetTypeId() == TYPEID_PLAYER)
3929 if (updateIndex>=PLAYER_END) return true;
3931 else
3933 if (updateIndex>=UNIT_END) return true;
3936 char* pvalue = strtok(NULL, " ");
3937 if (!pvalue)
3939 value=chr->GetUInt32Value(updateIndex);
3941 PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
3942 return true;
3945 value=atoi(pvalue);
3947 PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
3949 chr->SetUInt32Value(updateIndex,value);
3951 return true;
3954 bool ChatHandler::HandleBankCommand(const char* /*args*/)
3956 m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
3958 return true;
3961 bool ChatHandler::HandleChangeWeather(const char* args)
3963 if(!*args)
3964 return false;
3966 //Weather is OFF
3967 if (!sWorld.getConfig(CONFIG_WEATHER))
3969 SendSysMessage(LANG_WEATHER_DISABLED);
3970 SetSentErrorMessage(true);
3971 return false;
3974 //*Change the weather of a cell
3975 char* px = strtok((char*)args, " ");
3976 char* py = strtok(NULL, " ");
3978 if (!px || !py)
3979 return false;
3981 uint32 type = (uint32)atoi(px); //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
3982 float grade = (float)atof(py); //0 to 1, sending -1 is instand good weather
3984 Player *player = m_session->GetPlayer();
3985 uint32 zoneid = player->GetZoneId();
3987 Weather* wth = sWorld.FindWeather(zoneid);
3989 if(!wth)
3990 wth = sWorld.AddWeather(zoneid);
3991 if(!wth)
3993 SendSysMessage(LANG_NO_WEATHER);
3994 SetSentErrorMessage(true);
3995 return false;
3998 wth->SetWeather(WeatherType(type), grade);
4000 return true;
4003 bool ChatHandler::HandleSetValue(const char* args)
4005 if(!*args)
4006 return false;
4008 char* px = strtok((char*)args, " ");
4009 char* py = strtok(NULL, " ");
4010 char* pz = strtok(NULL, " ");
4012 if (!px || !py)
4013 return false;
4015 Unit* target = getSelectedUnit();
4016 if(!target)
4018 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4019 SetSentErrorMessage(true);
4020 return false;
4023 uint64 guid = target->GetGUID();
4025 uint32 Opcode = (uint32)atoi(px);
4026 if(Opcode >= target->GetValuesCount())
4028 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4029 return false;
4031 uint32 iValue;
4032 float fValue;
4033 bool isint32 = true;
4034 if(pz)
4035 isint32 = (bool)atoi(pz);
4036 if(isint32)
4038 iValue = (uint32)atoi(py);
4039 sLog.outDebug(GetMangosString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4040 target->SetUInt32Value( Opcode , iValue );
4041 PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4043 else
4045 fValue = (float)atof(py);
4046 sLog.outDebug(GetMangosString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4047 target->SetFloatValue( Opcode , fValue );
4048 PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4051 return true;
4054 bool ChatHandler::HandleGetValue(const char* args)
4056 if(!*args)
4057 return false;
4059 char* px = strtok((char*)args, " ");
4060 char* pz = strtok(NULL, " ");
4062 if (!px)
4063 return false;
4065 Unit* target = getSelectedUnit();
4066 if(!target)
4068 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4069 SetSentErrorMessage(true);
4070 return false;
4073 uint64 guid = target->GetGUID();
4075 uint32 Opcode = (uint32)atoi(px);
4076 if(Opcode >= target->GetValuesCount())
4078 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4079 return false;
4081 uint32 iValue;
4082 float fValue;
4083 bool isint32 = true;
4084 if(pz)
4085 isint32 = (bool)atoi(pz);
4087 if(isint32)
4089 iValue = target->GetUInt32Value( Opcode );
4090 sLog.outDebug(GetMangosString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4091 PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode, iValue);
4093 else
4095 fValue = target->GetFloatValue( Opcode );
4096 sLog.outDebug(GetMangosString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4097 PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4100 return true;
4103 bool ChatHandler::HandleSet32Bit(const char* args)
4105 if(!*args)
4106 return false;
4108 char* px = strtok((char*)args, " ");
4109 char* py = strtok(NULL, " ");
4111 if (!px || !py)
4112 return false;
4114 uint32 Opcode = (uint32)atoi(px);
4115 uint32 Value = (uint32)atoi(py);
4116 if (Value > 32) //uint32 = 32 bits
4117 return false;
4119 sLog.outDebug(GetMangosString(LANG_SET_32BIT), Opcode, Value);
4121 m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4123 PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4124 return true;
4127 bool ChatHandler::HandleMod32Value(const char* args)
4129 if(!*args)
4130 return false;
4132 char* px = strtok((char*)args, " ");
4133 char* py = strtok(NULL, " ");
4135 if (!px || !py)
4136 return false;
4138 uint32 Opcode = (uint32)atoi(px);
4139 int Value = atoi(py);
4141 if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4143 PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4144 return false;
4147 sLog.outDebug(GetMangosString(LANG_CHANGE_32BIT), Opcode, Value);
4149 int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4151 CurrentValue += Value;
4152 m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4154 PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4156 return true;
4159 bool ChatHandler::HandleAddTeleCommand(const char * args)
4161 if(!*args)
4162 return false;
4164 Player *player=m_session->GetPlayer();
4165 if (!player)
4166 return false;
4168 std::string name = args;
4170 if(objmgr.GetGameTele(name))
4172 SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4173 SetSentErrorMessage(true);
4174 return false;
4177 GameTele tele;
4178 tele.position_x = player->GetPositionX();
4179 tele.position_y = player->GetPositionY();
4180 tele.position_z = player->GetPositionZ();
4181 tele.orientation = player->GetOrientation();
4182 tele.mapId = player->GetMapId();
4183 tele.name = name;
4185 if(objmgr.AddGameTele(tele))
4187 SendSysMessage(LANG_COMMAND_TP_ADDED);
4189 else
4191 SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4192 SetSentErrorMessage(true);
4193 return false;
4196 return true;
4199 bool ChatHandler::HandleDelTeleCommand(const char * args)
4201 if(!*args)
4202 return false;
4204 std::string name = args;
4206 if(!objmgr.DeleteGameTele(name))
4208 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4209 SetSentErrorMessage(true);
4210 return false;
4213 SendSysMessage(LANG_COMMAND_TP_DELETED);
4214 return true;
4217 bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4219 Unit *unit = getSelectedUnit();
4220 if(!unit)
4222 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4223 SetSentErrorMessage(true);
4224 return false;
4227 char const* talentStr = GetMangosString(LANG_TALENT);
4228 char const* passiveStr = GetMangosString(LANG_PASSIVE);
4230 Unit::AuraMap const& uAuras = unit->GetAuras();
4231 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4232 for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4234 bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4235 PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4236 itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4237 itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4238 (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4239 IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4241 for (int i = 0; i < TOTAL_AURAS; i++)
4243 Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4244 if (uAuraList.empty()) continue;
4245 PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4246 for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4248 bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4249 PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4250 (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4251 IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4254 return true;
4257 bool ChatHandler::HandleResetHonorCommand (const char * args)
4259 char* pName = strtok((char*)args, "");
4260 Player *player = NULL;
4261 if (pName)
4263 std::string name = pName;
4264 if(!normalizePlayerName(name))
4266 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4267 SetSentErrorMessage(true);
4268 return false;
4271 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4272 player = objmgr.GetPlayer(guid);
4274 else
4275 player = getSelectedPlayer();
4277 if(!player)
4279 SendSysMessage(LANG_NO_CHAR_SELECTED);
4280 return true;
4283 player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4284 player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4285 player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4286 player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4287 player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4289 return true;
4292 static bool HandleResetStatsOrLevelHelper(Player* player)
4294 PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4295 if(!info) return false;
4297 ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4298 if(!cEntry)
4300 sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4301 return false;
4304 uint8 powertype = cEntry->powerType;
4306 uint32 unitfield;
4307 if(powertype == POWER_RAGE)
4308 unitfield = 0x1100EE00;
4309 else if(powertype == POWER_ENERGY)
4310 unitfield = 0x00000000;
4311 else if(powertype == POWER_MANA)
4312 unitfield = 0x0000EE00;
4313 else
4315 sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4316 return false;
4319 // reset m_form if no aura
4320 if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4321 player->m_form = FORM_NONE;
4323 player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4324 player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f );
4326 player->setFactionForRace(player->getRace());
4328 player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4330 // reset only if player not in some form;
4331 if(player->m_form==FORM_NONE)
4333 switch(player->getGender())
4335 case GENDER_FEMALE:
4336 player->SetDisplayId(info->displayId_f);
4337 player->SetNativeDisplayId(info->displayId_f);
4338 break;
4339 case GENDER_MALE:
4340 player->SetDisplayId(info->displayId_m);
4341 player->SetNativeDisplayId(info->displayId_m);
4342 break;
4343 default:
4344 break;
4348 // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4349 player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4350 player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4351 player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4353 player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4355 //-1 is default value
4356 player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4358 //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4359 return true;
4362 bool ChatHandler::HandleResetLevelCommand(const char * args)
4364 char* pName = strtok((char*)args, "");
4365 Player *player = NULL;
4366 if (pName)
4368 std::string name = pName;
4369 if(!normalizePlayerName(name))
4371 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4372 SetSentErrorMessage(true);
4373 return false;
4376 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4377 player = objmgr.GetPlayer(guid);
4379 else
4380 player = getSelectedPlayer();
4382 if(!player)
4384 SendSysMessage(LANG_NO_CHAR_SELECTED);
4385 SetSentErrorMessage(true);
4386 return false;
4389 if(!HandleResetStatsOrLevelHelper(player))
4390 return false;
4392 player->SetLevel(1);
4393 player->InitStatsForLevel(true);
4394 player->InitTaxiNodesForLevel();
4395 player->InitTalentForLevel();
4396 player->SetUInt32Value(PLAYER_XP,0);
4398 // reset level to summoned pet
4399 Pet* pet = player->GetPet();
4400 if(pet && pet->getPetType()==SUMMON_PET)
4401 pet->InitStatsForLevel(1);
4403 return true;
4406 bool ChatHandler::HandleResetStatsCommand(const char * args)
4408 char* pName = strtok((char*)args, "");
4409 Player *player = NULL;
4410 if (pName)
4412 std::string name = pName;
4413 if(!normalizePlayerName(name))
4415 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4416 SetSentErrorMessage(true);
4417 return false;
4420 uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4421 player = objmgr.GetPlayer(guid);
4423 else
4424 player = getSelectedPlayer();
4426 if(!player)
4428 SendSysMessage(LANG_NO_CHAR_SELECTED);
4429 SetSentErrorMessage(true);
4430 return false;
4433 if(!HandleResetStatsOrLevelHelper(player))
4434 return false;
4436 player->InitStatsForLevel(true);
4437 player->InitTaxiNodesForLevel();
4438 player->InitTalentForLevel();
4440 return true;
4443 bool ChatHandler::HandleResetSpellsCommand(const char * args)
4445 char* pName = strtok((char*)args, "");
4446 Player *player = NULL;
4447 uint64 playerGUID = 0;
4448 if (pName)
4450 std::string name = pName;
4452 if(!normalizePlayerName(name))
4454 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4455 SetSentErrorMessage(true);
4456 return false;
4459 player = objmgr.GetPlayer(name.c_str());
4460 if(!player)
4461 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4463 else
4464 player = getSelectedPlayer();
4466 if(!player && !playerGUID)
4468 SendSysMessage(LANG_NO_CHAR_SELECTED);
4469 SetSentErrorMessage(true);
4470 return false;
4473 if(player)
4475 player->resetSpells();
4477 ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4479 if(m_session->GetPlayer()!=player)
4480 PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4482 else
4484 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4485 PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4488 return true;
4491 bool ChatHandler::HandleResetTalentsCommand(const char * args)
4493 char* pName = strtok((char*)args, "");
4494 Player *player = NULL;
4495 uint64 playerGUID = 0;
4496 if (pName)
4498 std::string name = pName;
4499 if(!normalizePlayerName(name))
4501 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4502 SetSentErrorMessage(true);
4503 return false;
4506 player = objmgr.GetPlayer(name.c_str());
4507 if(!player)
4508 playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4510 else
4511 player = getSelectedPlayer();
4513 if(!player && !playerGUID)
4515 SendSysMessage(LANG_NO_CHAR_SELECTED);
4516 SetSentErrorMessage(true);
4517 return false;
4520 if(player)
4522 player->resetTalents(true);
4524 ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4526 if(m_session->GetPlayer()!=player)
4527 PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4529 else
4531 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4532 PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4535 return true;
4538 bool ChatHandler::HandleResetAllCommand(const char * args)
4540 if(!*args)
4541 return false;
4543 std::string casename = args;
4545 AtLoginFlags atLogin;
4547 // Command specially created as single command to prevent using short case names
4548 if(casename=="spells")
4550 atLogin = AT_LOGIN_RESET_SPELLS;
4551 sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4553 else if(casename=="talents")
4555 atLogin = AT_LOGIN_RESET_TALENTS;
4556 sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4558 else
4560 PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4561 SetSentErrorMessage(true);
4562 return false;
4565 CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4566 HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4567 for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4568 itr->second->SetAtLoginFlag(atLogin);
4570 return true;
4573 bool ChatHandler::HandleShutDownCommand(const char* args)
4575 if(!*args)
4576 return false;
4578 if(std::string(args)=="cancel")
4580 sWorld.ShutdownCancel();
4582 else
4584 int32 time = atoi(args);
4586 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4587 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4588 return false;
4590 sWorld.ShutdownServ(time);
4592 return true;
4595 bool ChatHandler::HandleRestartCommand(const char* args)
4597 if(!*args)
4598 return false;
4600 if(std::string(args)=="cancel")
4602 sWorld.ShutdownCancel();
4604 else
4606 int32 time = atoi(args);
4608 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4609 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4610 return false;
4612 sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4614 return true;
4617 bool ChatHandler::HandleIdleRestartCommand(const char* args)
4619 if(!*args)
4620 return false;
4622 if(std::string(args)=="cancel")
4624 sWorld.ShutdownCancel();
4626 else
4628 int32 time = atoi(args);
4630 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4631 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4632 return false;
4634 sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4636 return true;
4639 bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4641 if(!*args)
4642 return false;
4644 if(std::string(args)=="cancel")
4646 sWorld.ShutdownCancel();
4648 else
4650 int32 time = atoi(args);
4652 ///- Prevent interpret wrong arg value as 0 secs shutdown time
4653 if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4654 return false;
4656 sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4658 return true;
4661 bool ChatHandler::HandleAddQuest(const char* args)
4663 Player* player = getSelectedPlayer();
4664 if(!player)
4666 SendSysMessage(LANG_NO_CHAR_SELECTED);
4667 SetSentErrorMessage(true);
4668 return false;
4671 // .addquest #entry'
4672 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4673 char* cId = extractKeyFromLink((char*)args,"Hquest");
4674 if(!cId)
4675 return false;
4677 uint32 entry = atol(cId);
4679 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4681 if(!pQuest)
4683 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4684 SetSentErrorMessage(true);
4685 return false;
4688 // check item starting quest (it can work incorrectly if added without item in inventory)
4689 for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4691 ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4692 if (!pProto)
4693 continue;
4695 if (pProto->StartQuest == entry)
4697 PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4698 SetSentErrorMessage(true);
4699 return false;
4703 // ok, normal (creature/GO starting) quest
4704 if( player->CanAddQuest( pQuest, true ) )
4706 player->AddQuest( pQuest, NULL );
4708 if ( player->CanCompleteQuest( entry ) )
4709 player->CompleteQuest( entry );
4712 return true;
4715 bool ChatHandler::HandleRemoveQuest(const char* args)
4717 Player* player = getSelectedPlayer();
4718 if(!player)
4720 SendSysMessage(LANG_NO_CHAR_SELECTED);
4721 SetSentErrorMessage(true);
4722 return false;
4725 // .removequest #entry'
4726 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4727 char* cId = extractKeyFromLink((char*)args,"Hquest");
4728 if(!cId)
4729 return false;
4731 uint32 entry = atol(cId);
4733 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4735 if(!pQuest)
4737 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4738 SetSentErrorMessage(true);
4739 return false;
4742 // remove all quest entries for 'entry' from quest log
4743 for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4745 uint32 quest = player->GetQuestSlotQuestId(slot);
4746 if(quest==entry)
4748 player->SetQuestSlot(slot,0);
4750 // we ignore unequippable quest items in this case, its' still be equipped
4751 player->TakeQuestSourceItem( quest, false );
4755 // set quest status to not started (will updated in DB at next save)
4756 player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4758 // reset rewarded for restart repeatable quest
4759 player->getQuestStatusMap()[entry].m_rewarded = false;
4761 SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4762 return true;
4765 bool ChatHandler::HandleCompleteQuest(const char* args)
4767 Player* player = getSelectedPlayer();
4768 if(!player)
4770 SendSysMessage(LANG_NO_CHAR_SELECTED);
4771 SetSentErrorMessage(true);
4772 return false;
4775 // .quest complete #entry
4776 // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4777 char* cId = extractKeyFromLink((char*)args,"Hquest");
4778 if(!cId)
4779 return false;
4781 uint32 entry = atol(cId);
4783 Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4785 // If player doesn't have the quest
4786 if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4788 PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4789 SetSentErrorMessage(true);
4790 return false;
4793 // Add quest items for quests that require items
4794 for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4796 uint32 id = pQuest->ReqItemId[x];
4797 uint32 count = pQuest->ReqItemCount[x];
4798 if(!id || !count)
4799 continue;
4801 uint32 curItemCount = player->GetItemCount(id,true);
4803 ItemPosCountVec dest;
4804 uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4805 if( msg == EQUIP_ERR_OK )
4807 Item* item = player->StoreNewItem( dest, id, true);
4808 player->SendNewItem(item,count-curItemCount,true,false);
4812 // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4813 for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4815 uint32 creature = pQuest->ReqCreatureOrGOId[i];
4816 uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4818 if(uint32 spell_id = pQuest->ReqSpell[i])
4820 for(uint16 z = 0; z < creaturecount; ++z)
4821 player->CastedCreatureOrGO(creature,0,spell_id);
4823 else if(creature > 0)
4825 for(uint16 z = 0; z < creaturecount; ++z)
4826 player->KilledMonster(creature,0);
4828 else if(creature < 0)
4830 for(uint16 z = 0; z < creaturecount; ++z)
4831 player->CastedCreatureOrGO(creature,0,0);
4835 // If the quest requires reputation to complete
4836 if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4838 uint32 repValue = pQuest->GetRepObjectiveValue();
4839 uint32 curRep = player->GetReputation(repFaction);
4840 if(curRep < repValue)
4842 FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4843 player->SetFactionReputation(factionEntry,repValue);
4847 // If the quest requires money
4848 int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4849 if(ReqOrRewMoney < 0)
4850 player->ModifyMoney(-ReqOrRewMoney);
4852 player->CompleteQuest(entry);
4853 return true;
4856 bool ChatHandler::HandleBanAccountCommand(const char* args)
4858 return HandleBanHelper(BAN_ACCOUNT,args);
4861 bool ChatHandler::HandleBanCharacterCommand(const char* args)
4863 return HandleBanHelper(BAN_CHARACTER,args);
4866 bool ChatHandler::HandleBanIPCommand(const char* args)
4868 return HandleBanHelper(BAN_IP,args);
4871 bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4873 if(!args)
4874 return false;
4876 char* cnameOrIP = strtok ((char*)args, " ");
4877 if (!cnameOrIP)
4878 return false;
4880 std::string nameOrIP = cnameOrIP;
4882 char* duration = strtok (NULL," ");
4883 if(!duration || !atoi(duration))
4884 return false;
4886 char* reason = strtok (NULL,"");
4887 if(!reason)
4888 return false;
4890 switch(mode)
4892 case BAN_ACCOUNT:
4893 if(!AccountMgr::normilizeString(nameOrIP))
4895 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4896 SetSentErrorMessage(true);
4897 return false;
4899 break;
4900 case BAN_CHARACTER:
4901 if(!normalizePlayerName(nameOrIP))
4903 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4904 SetSentErrorMessage(true);
4905 return false;
4907 break;
4908 case BAN_IP:
4909 if(!IsIPAddress(nameOrIP.c_str()))
4910 return false;
4911 break;
4914 switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4916 case BAN_SUCCESS:
4917 if(atoi(duration)>0)
4918 PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
4919 else
4920 PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
4921 break;
4922 case BAN_SYNTAX_ERROR:
4923 return false;
4924 case BAN_NOTFOUND:
4925 switch(mode)
4927 default:
4928 PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
4929 break;
4930 case BAN_CHARACTER:
4931 PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
4932 break;
4933 case BAN_IP:
4934 PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
4935 break;
4937 SetSentErrorMessage(true);
4938 return false;
4941 return true;
4944 bool ChatHandler::HandleUnBanAccountCommand(const char* args)
4946 return HandleUnBanHelper(BAN_ACCOUNT,args);
4949 bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
4951 return HandleUnBanHelper(BAN_CHARACTER,args);
4954 bool ChatHandler::HandleUnBanIPCommand(const char* args)
4956 return HandleUnBanHelper(BAN_IP,args);
4959 bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
4961 if(!args)
4962 return false;
4964 char* cnameOrIP = strtok ((char*)args, " ");
4965 if(!cnameOrIP)
4966 return false;
4968 std::string nameOrIP = cnameOrIP;
4970 switch(mode)
4972 case BAN_ACCOUNT:
4973 if(!AccountMgr::normilizeString(nameOrIP))
4975 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4976 SetSentErrorMessage(true);
4977 return false;
4979 break;
4980 case BAN_CHARACTER:
4981 if(!normalizePlayerName(nameOrIP))
4983 SendSysMessage(LANG_PLAYER_NOT_FOUND);
4984 SetSentErrorMessage(true);
4985 return false;
4987 break;
4988 case BAN_IP:
4989 if(!IsIPAddress(nameOrIP.c_str()))
4990 return false;
4991 break;
4994 if(sWorld.RemoveBanAccount(mode,nameOrIP))
4995 PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
4996 else
4997 PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
4999 return true;
5002 bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5004 if(!args)
5005 return false;
5007 char* cname = strtok((char*)args, "");
5008 if(!cname)
5009 return false;
5011 std::string account_name = cname;
5012 if(!AccountMgr::normilizeString(account_name))
5014 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5015 SetSentErrorMessage(true);
5016 return false;
5019 uint32 accountid = accmgr.GetId(account_name);
5020 if(!accountid)
5022 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5023 return true;
5026 return HandleBanInfoHelper(accountid,account_name.c_str());
5029 bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5031 if(!args)
5032 return false;
5034 char* cname = strtok ((char*)args, "");
5035 if(!cname)
5036 return false;
5038 std::string name = cname;
5039 if(!normalizePlayerName(name))
5041 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5042 SetSentErrorMessage(true);
5043 return false;
5046 uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5047 if(!accountid)
5049 SendSysMessage(LANG_PLAYER_NOT_FOUND);
5050 SetSentErrorMessage(true);
5051 return false;
5054 std::string accountname;
5055 if(!accmgr.GetName(accountid,accountname))
5057 PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5058 return true;
5061 return HandleBanInfoHelper(accountid,accountname.c_str());
5064 bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5066 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);
5067 if(!result)
5069 PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5070 return true;
5073 PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5076 Field* fields = result->Fetch();
5078 time_t unbandate = time_t(fields[3].GetUInt64());
5079 bool active = false;
5080 if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5081 active = true;
5082 bool permanent = (fields[1].GetUInt64() == (uint64)0);
5083 std::string bantime = permanent?GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5084 PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5085 fields[0].GetString(), bantime.c_str(), active ? GetMangosString(LANG_BANINFO_YES):GetMangosString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5086 }while (result->NextRow());
5088 delete result;
5089 return true;
5092 bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5094 if(!args)
5095 return false;
5097 char* cIP = strtok ((char*)args, "");
5098 if(!cIP)
5099 return false;
5101 if (!IsIPAddress(cIP))
5102 return false;
5104 std::string IP = cIP;
5106 loginDatabase.escape_string(IP);
5107 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());
5108 if(!result)
5110 PSendSysMessage(LANG_BANINFO_NOIP);
5111 return true;
5114 Field *fields = result->Fetch();
5115 bool permanent = !fields[6].GetUInt64();
5116 PSendSysMessage(LANG_BANINFO_IPENTRY,
5117 fields[0].GetString(), fields[1].GetString(), permanent ? GetMangosString(LANG_BANINFO_NEVER):fields[2].GetString(),
5118 permanent ? GetMangosString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5119 delete result;
5120 return true;
5123 bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5125 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5127 char* cFilter = strtok ((char*)args, " ");
5128 if(!cFilter)
5129 return false;
5131 std::string filter = cFilter;
5132 loginDatabase.escape_string(filter);
5133 QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5134 if (!result)
5136 PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5137 return true;
5140 return HandleBanListHelper(result);
5143 bool ChatHandler::HandleBanListAccountCommand(const char* args)
5145 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5147 char* cFilter = strtok((char*)args, " ");
5148 std::string filter = cFilter ? cFilter : "";
5149 loginDatabase.escape_string(filter);
5151 QueryResult* result;
5153 if(filter.empty())
5155 result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5156 " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5158 else
5160 result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5161 " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5162 filter.c_str());
5165 if (!result)
5167 PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5168 return true;
5171 return HandleBanListHelper(result);
5174 bool ChatHandler::HandleBanListHelper(QueryResult* result)
5176 PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5178 // Chat short output
5179 if(m_session)
5183 Field* fields = result->Fetch();
5184 uint32 accountid = fields[0].GetUInt32();
5186 QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5187 if(banresult)
5189 Field* fields2 = banresult->Fetch();
5190 PSendSysMessage("%s",fields2[0].GetString());
5191 delete banresult;
5193 } while (result->NextRow());
5195 // Console wide output
5196 else
5198 SendSysMessage(LANG_BANLIST_ACCOUNTS);
5199 SendSysMessage("===============================================================================");
5200 SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5203 SendSysMessage("-------------------------------------------------------------------------------");
5204 Field *fields = result->Fetch();
5205 uint32 account_id = fields[0].GetUInt32 ();
5207 std::string account_name;
5209 // "account" case, name can be get in same query
5210 if(result->GetFieldCount() > 1)
5211 account_name = fields[1].GetCppString();
5212 // "character" case, name need extract from another DB
5213 else
5214 accmgr.GetName (account_id,account_name);
5216 // No SQL injection. id is uint32.
5217 QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5218 if (banInfo)
5220 Field *fields2 = banInfo->Fetch();
5223 time_t t_ban = fields2[0].GetUInt64();
5224 tm* aTm_ban = localtime(&t_ban);
5226 if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5228 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5229 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,
5230 fields2[2].GetString(),fields2[3].GetString());
5232 else
5234 time_t t_unban = fields2[1].GetUInt64();
5235 tm* aTm_unban = localtime(&t_unban);
5236 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5237 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,
5238 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5239 fields2[2].GetString(),fields2[3].GetString());
5241 }while ( banInfo->NextRow() );
5242 delete banInfo;
5244 }while( result->NextRow() );
5245 SendSysMessage("===============================================================================");
5248 delete result;
5249 return true;
5252 bool ChatHandler::HandleBanListIPCommand(const char* args)
5254 loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5256 char* cFilter = strtok((char*)args, " ");
5257 std::string filter = cFilter ? cFilter : "";
5258 loginDatabase.escape_string(filter);
5260 QueryResult* result;
5262 if(filter.empty())
5264 result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5265 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5266 " ORDER BY unbandate" );
5268 else
5270 result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5271 " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5272 " ORDER BY unbandate",filter.c_str() );
5275 if(!result)
5277 PSendSysMessage(LANG_BANLIST_NOIP);
5278 return true;
5281 PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5282 // Chat short output
5283 if(m_session)
5287 Field* fields = result->Fetch();
5288 PSendSysMessage("%s",fields[0].GetString());
5289 } while (result->NextRow());
5291 // Console wide output
5292 else
5294 SendSysMessage(LANG_BANLIST_IPS);
5295 SendSysMessage("===============================================================================");
5296 SendSysMessage(LANG_BANLIST_IPS_HEADER);
5299 SendSysMessage("-------------------------------------------------------------------------------");
5300 Field *fields = result->Fetch();
5301 time_t t_ban = fields[1].GetUInt64();
5302 tm* aTm_ban = localtime(&t_ban);
5303 if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5305 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d| permanent |%-15.15s|%-15.15s|",
5306 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,
5307 fields[3].GetString(), fields[4].GetString());
5309 else
5311 time_t t_unban = fields[2].GetUInt64();
5312 tm* aTm_unban = localtime(&t_unban);
5313 PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5314 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,
5315 aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5316 fields[3].GetString(), fields[4].GetString());
5318 }while( result->NextRow() );
5319 SendSysMessage("===============================================================================");
5322 delete result;
5323 return true;
5326 bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5328 Player* pl = m_session->GetPlayer();
5330 // accept only explicitly selected target (not implicitly self targeting case)
5331 Unit* target = getSelectedUnit();
5332 if(pl->GetSelection() && target)
5334 if(target->GetTypeId()!=TYPEID_UNIT)
5336 SendSysMessage(LANG_SELECT_CREATURE);
5337 SetSentErrorMessage(true);
5338 return false;
5341 if(target->isDead())
5342 ((Creature*)target)->Respawn();
5343 return true;
5346 CellPair p(MaNGOS::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5347 Cell cell(p);
5348 cell.data.Part.reserved = ALL_DISTRICT;
5349 cell.SetNoCreate();
5351 MaNGOS::RespawnDo u_do;
5352 MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo> worker(u_do);
5354 TypeContainerVisitor<MaNGOS::WorldObjectWorker<MaNGOS::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5355 CellLock<GridReadGuard> cell_lock(cell, p);
5356 cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5358 return true;
5361 bool ChatHandler::HandleFlyModeCommand(const char* args)
5363 if(!args)
5364 return false;
5366 Unit *unit = getSelectedUnit();
5367 if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5368 unit = m_session->GetPlayer();
5370 WorldPacket data(12);
5371 if (strncmp(args, "on", 3) == 0)
5372 data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5373 else if (strncmp(args, "off", 4) == 0)
5374 data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5375 else
5377 SendSysMessage(LANG_USE_BOL);
5378 return false;
5380 data.append(unit->GetPackGUID());
5381 data << uint32(0); // unknown
5382 unit->SendMessageToSet(&data, true);
5383 PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5384 return true;
5387 bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5389 if(!args)
5390 return false;
5392 char * file = strtok((char*)args, " ");
5393 if(!file)
5394 return false;
5396 char * account = strtok(NULL, " ");
5397 if(!account)
5398 return false;
5400 std::string account_name = account;
5401 if(!AccountMgr::normilizeString(account_name))
5403 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5404 SetSentErrorMessage(true);
5405 return false;
5408 uint32 account_id = accmgr.GetId(account_name);
5409 if(!account_id)
5411 account_id = atoi(account); // use original string
5412 if(!account_id)
5414 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5415 SetSentErrorMessage(true);
5416 return false;
5420 if(!accmgr.GetName(account_id,account_name))
5422 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5423 SetSentErrorMessage(true);
5424 return false;
5427 char* guid_str = NULL;
5428 char* name_str = strtok(NULL, " ");
5430 std::string name;
5431 if(name_str)
5433 name = name_str;
5434 // normalize the name if specified and check if it exists
5435 if(!normalizePlayerName(name))
5437 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5438 SetSentErrorMessage(true);
5439 return false;
5442 if(!ObjectMgr::IsValidName(name,true))
5444 PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5445 SetSentErrorMessage(true);
5446 return false;
5449 guid_str = strtok(NULL, " ");
5452 uint32 guid = 0;
5454 if(guid_str)
5456 guid = atoi(guid_str);
5457 if(!guid)
5459 PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5460 SetSentErrorMessage(true);
5461 return false;
5464 if(objmgr.GetPlayerAccountIdByGUID(guid))
5466 PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5467 SetSentErrorMessage(true);
5468 return false;
5472 switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5474 case DUMP_SUCCESS:
5475 PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5476 break;
5477 case DUMP_FILE_OPEN_ERROR:
5478 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5479 SetSentErrorMessage(true);
5480 return false;
5481 case DUMP_FILE_BROKEN:
5482 PSendSysMessage(LANG_DUMP_BROKEN,file);
5483 SetSentErrorMessage(true);
5484 return false;
5485 case DUMP_TOO_MANY_CHARS:
5486 PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5487 SetSentErrorMessage(true);
5488 return false;
5489 default:
5490 PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5491 SetSentErrorMessage(true);
5492 return false;
5495 return true;
5498 bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
5500 if(!args)
5501 return false;
5503 uint32 newEntryNum = atoi(args);
5504 if(!newEntryNum)
5505 return false;
5507 Unit* unit = getSelectedUnit();
5508 if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5510 SendSysMessage(LANG_SELECT_CREATURE);
5511 SetSentErrorMessage(true);
5512 return false;
5514 Creature* creature = (Creature*)unit;
5515 if(creature->UpdateEntry(newEntryNum))
5516 SendSysMessage(LANG_DONE);
5517 else
5518 SendSysMessage(LANG_ERROR);
5519 return true;
5522 bool ChatHandler::HandleWritePDumpCommand(const char *args)
5524 if(!args)
5525 return false;
5527 char* file = strtok((char*)args, " ");
5528 char* p2 = strtok(NULL, " ");
5530 if(!file || !p2)
5531 return false;
5533 uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5534 if(!guid)
5535 guid = atoi(p2);
5537 if(!objmgr.GetPlayerAccountIdByGUID(guid))
5539 PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5540 SetSentErrorMessage(true);
5541 return false;
5544 switch(PlayerDumpWriter().WriteDump(file, guid))
5546 case DUMP_SUCCESS:
5547 PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5548 break;
5549 case DUMP_FILE_OPEN_ERROR:
5550 PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5551 SetSentErrorMessage(true);
5552 return false;
5553 default:
5554 PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5555 SetSentErrorMessage(true);
5556 return false;
5559 return true;
5562 bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5564 Unit* unit = getSelectedUnit();
5565 if(!unit)
5567 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5568 SetSentErrorMessage(true);
5569 return false;
5572 PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5574 MotionMaster* mm = unit->GetMotionMaster();
5575 for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5577 switch((*itr)->GetMovementGeneratorType())
5579 case IDLE_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_IDLE); break;
5580 case RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_RANDOM); break;
5581 case WAYPOINT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_WAYPOINT); break;
5582 case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5583 case CONFUSED_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_CONFUSED); break;
5584 case TARGETED_MOTION_TYPE:
5586 if(unit->GetTypeId()==TYPEID_PLAYER)
5588 TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5589 Unit* target = mgen->GetTarget();
5590 if(target)
5591 PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5592 else
5593 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5595 else
5597 TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5598 Unit* target = mgen->GetTarget();
5599 if(target)
5600 PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5601 else
5602 SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5604 break;
5606 case HOME_MOTION_TYPE:
5607 if(unit->GetTypeId()==TYPEID_UNIT)
5609 float x,y,z;
5610 (*itr)->GetDestination(x,y,z);
5611 PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5613 else
5614 SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5615 break;
5616 case FLIGHT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FLIGHT); break;
5617 case POINT_MOTION_TYPE:
5619 float x,y,z;
5620 (*itr)->GetDestination(x,y,z);
5621 PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5622 break;
5624 case FLEEING_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_FEAR); break;
5625 case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT); break;
5626 default:
5627 PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5628 break;
5631 return true;
5634 bool ChatHandler::HandlePLimitCommand(const char *args)
5636 if(*args)
5638 char* param = strtok((char*)args, " ");
5639 if(!param)
5640 return false;
5642 int l = strlen(param);
5644 if( strncmp(param,"player",l) == 0 )
5645 sWorld.SetPlayerLimit(-SEC_PLAYER);
5646 else if(strncmp(param,"moderator",l) == 0 )
5647 sWorld.SetPlayerLimit(-SEC_MODERATOR);
5648 else if(strncmp(param,"gamemaster",l) == 0 )
5649 sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5650 else if(strncmp(param,"administrator",l) == 0 )
5651 sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5652 else if(strncmp(param,"reset",l) == 0 )
5653 sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5654 else
5656 int val = atoi(param);
5657 if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5659 sWorld.SetPlayerLimit(val);
5662 // kick all low security level players
5663 if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5664 sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5667 uint32 pLimit = sWorld.GetPlayerAmountLimit();
5668 AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5669 char const* secName = "";
5670 switch(allowedAccountType)
5672 case SEC_PLAYER: secName = "Player"; break;
5673 case SEC_MODERATOR: secName = "Moderator"; break;
5674 case SEC_GAMEMASTER: secName = "Gamemaster"; break;
5675 case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5676 default: secName = "<unknown>"; break;
5679 PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5681 return true;
5684 bool ChatHandler::HandleCastCommand(const char* args)
5686 if(!*args)
5687 return false;
5689 Unit* target = getSelectedUnit();
5691 if(!target)
5693 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5694 SetSentErrorMessage(true);
5695 return false;
5698 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5699 uint32 spell = extractSpellIdFromLink((char*)args);
5700 if(!spell)
5701 return false;
5703 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5704 if(!spellInfo)
5705 return false;
5707 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5709 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5710 SetSentErrorMessage(true);
5711 return false;
5714 char* trig_str = strtok(NULL, " ");
5715 if(trig_str)
5717 int l = strlen(trig_str);
5718 if(strncmp(trig_str,"triggered",l) != 0 )
5719 return false;
5722 bool triggered = (trig_str != NULL);
5724 m_session->GetPlayer()->CastSpell(target,spell,triggered);
5726 return true;
5729 bool ChatHandler::HandleCastBackCommand(const char* args)
5731 Creature* caster = getSelectedCreature();
5733 if(!caster)
5735 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5736 SetSentErrorMessage(true);
5737 return false;
5740 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5741 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5742 uint32 spell = extractSpellIdFromLink((char*)args);
5743 if(!spell || !sSpellStore.LookupEntry(spell))
5744 return false;
5746 char* trig_str = strtok(NULL, " ");
5747 if(trig_str)
5749 int l = strlen(trig_str);
5750 if(strncmp(trig_str,"triggered",l) != 0 )
5751 return false;
5754 bool triggered = (trig_str != NULL);
5756 // update orientation at server
5757 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5759 // and client
5760 WorldPacket data;
5761 caster->BuildHeartBeatMsg(&data);
5762 caster->SendMessageToSet(&data,true);
5764 caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5766 return true;
5769 bool ChatHandler::HandleCastDistCommand(const char* args)
5771 if(!*args)
5772 return false;
5774 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5775 uint32 spell = extractSpellIdFromLink((char*)args);
5776 if(!spell)
5777 return false;
5779 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5780 if(!spellInfo)
5781 return false;
5783 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5785 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5786 SetSentErrorMessage(true);
5787 return false;
5790 char *distStr = strtok(NULL, " ");
5792 float dist = 0;
5794 if(distStr)
5795 sscanf(distStr, "%f", &dist);
5797 char* trig_str = strtok(NULL, " ");
5798 if(trig_str)
5800 int l = strlen(trig_str);
5801 if(strncmp(trig_str,"triggered",l) != 0 )
5802 return false;
5805 bool triggered = (trig_str != NULL);
5807 float x,y,z;
5808 m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5810 m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5811 return true;
5814 bool ChatHandler::HandleCastTargetCommand(const char* args)
5816 Creature* caster = getSelectedCreature();
5818 if(!caster)
5820 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5821 SetSentErrorMessage(true);
5822 return false;
5825 if(!caster->getVictim())
5827 SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5828 SetSentErrorMessage(true);
5829 return false;
5832 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5833 uint32 spell = extractSpellIdFromLink((char*)args);
5834 if(!spell || !sSpellStore.LookupEntry(spell))
5835 return false;
5837 char* trig_str = strtok(NULL, " ");
5838 if(trig_str)
5840 int l = strlen(trig_str);
5841 if(strncmp(trig_str,"triggered",l) != 0 )
5842 return false;
5845 bool triggered = (trig_str != NULL);
5847 // update orientation at server
5848 caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5850 // and client
5851 WorldPacket data;
5852 caster->BuildHeartBeatMsg(&data);
5853 caster->SendMessageToSet(&data,true);
5855 caster->CastSpell(caster->getVictim(),spell,triggered);
5857 return true;
5861 ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5862 Without this function 3rd party scripting library will get linking errors (unresolved external)
5863 when attempting to use the PointMovementGenerator
5865 bool ChatHandler::HandleComeToMeCommand(const char *args)
5867 Creature* caster = getSelectedCreature();
5869 if(!caster)
5871 SendSysMessage(LANG_SELECT_CREATURE);
5872 SetSentErrorMessage(true);
5873 return false;
5876 char* newFlagStr = strtok((char*)args, " ");
5878 if(!newFlagStr)
5879 return false;
5881 uint32 newFlags = atoi(newFlagStr);
5883 caster->SetUnitMovementFlags(newFlags);
5885 Player* pl = m_session->GetPlayer();
5887 caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5888 return true;
5891 bool ChatHandler::HandleCastSelfCommand(const char* args)
5893 if(!*args)
5894 return false;
5896 Unit* target = getSelectedUnit();
5898 if(!target)
5900 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5901 SetSentErrorMessage(true);
5902 return false;
5905 // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5906 uint32 spell = extractSpellIdFromLink((char*)args);
5907 if(!spell)
5908 return false;
5910 SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5911 if(!spellInfo)
5912 return false;
5914 if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5916 PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5917 SetSentErrorMessage(true);
5918 return false;
5921 target->CastSpell(target,spell,false);
5923 return true;
5926 std::string GetTimeString(uint32 time)
5928 uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
5929 std::ostringstream ss;
5930 if(days) ss << days << "d ";
5931 if(hours) ss << hours << "h ";
5932 ss << minute << "m";
5933 return ss.str();
5936 bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
5938 Player* player = getSelectedPlayer();
5939 if (!player) player = m_session->GetPlayer();
5940 uint32 counter = 0;
5941 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5943 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5944 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5946 InstanceSave *save = itr->second.save;
5947 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5948 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());
5949 counter++;
5952 PSendSysMessage("player binds: %d", counter);
5953 counter = 0;
5954 Group *group = player->GetGroup();
5955 if(group)
5957 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5959 Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
5960 for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
5962 InstanceSave *save = itr->second.save;
5963 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5964 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());
5965 counter++;
5969 PSendSysMessage("group binds: %d", counter);
5971 return true;
5974 bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
5976 if(!*args)
5977 return false;
5979 std::string cmd = args;
5980 if(cmd == "all")
5982 Player* player = getSelectedPlayer();
5983 if (!player) player = m_session->GetPlayer();
5984 uint32 counter = 0;
5985 for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
5987 Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
5988 for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
5990 if(itr->first != player->GetMapId())
5992 InstanceSave *save = itr->second.save;
5993 std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
5994 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());
5995 player->UnbindInstance(itr, i);
5996 counter++;
5998 else
5999 ++itr;
6002 PSendSysMessage("instances unbound: %d", counter);
6004 return true;
6007 bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6009 PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6010 PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6011 PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6012 PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6013 PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6014 return true;
6017 bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6019 Player* pl = m_session->GetPlayer();
6021 Map* map = pl->GetMap();
6022 if (!map->IsDungeon())
6024 PSendSysMessage("Map is not a dungeon.");
6025 SetSentErrorMessage(true);
6026 return false;
6029 if (!((InstanceMap*)map)->GetInstanceData())
6031 PSendSysMessage("Map has no instance data.");
6032 SetSentErrorMessage(true);
6033 return false;
6036 ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6037 return true;
6040 /// Display the list of GMs
6041 bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6043 ///- Get the accounts with GM Level >0
6044 QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6045 if(result)
6047 SendSysMessage(LANG_GMLIST);
6048 SendSysMessage("========================");
6049 SendSysMessage(LANG_GMLIST_HEADER);
6050 SendSysMessage("========================");
6052 ///- Circle through them. Display username and GM level
6055 Field *fields = result->Fetch();
6056 PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6057 }while( result->NextRow() );
6059 PSendSysMessage("========================");
6060 delete result;
6062 else
6063 PSendSysMessage(LANG_GMLIST_EMPTY);
6064 return true;
6067 /// Define the 'Message of the day' for the realm
6068 bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6070 sWorld.SetMotd(args);
6071 PSendSysMessage(LANG_MOTD_NEW, args);
6072 return true;
6075 /// Set/Unset the expansion level for an account
6076 bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6078 ///- Get the command line arguments
6079 char *szAcc = strtok((char*)args," ");
6080 char *szExp = strtok(NULL," ");
6082 if(!szAcc)
6083 return false;
6085 std::string account_name;
6086 uint32 account_id;
6088 if(!szExp)
6090 Player* player = getSelectedPlayer();
6091 if(!player)
6092 return false;
6094 account_id = player->GetSession()->GetAccountId();
6095 accmgr.GetName(account_id,account_name);
6096 szExp = szAcc;
6098 else
6100 ///- Convert Account name to Upper Format
6101 account_name = szAcc;
6102 if(!AccountMgr::normilizeString(account_name))
6104 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6105 SetSentErrorMessage(true);
6106 return false;
6109 account_id = accmgr.GetId(account_name);
6110 if(!account_id)
6112 PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6113 SetSentErrorMessage(true);
6114 return false;
6118 int lev=atoi(szExp); //get int anyway (0 if error)
6119 if(lev < 0)
6120 return false;
6122 // No SQL injection
6123 loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6124 PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6125 return true;
6128 //Send items by mail
6129 bool ChatHandler::HandleSendItemsCommand(const char* args)
6131 if(!*args)
6132 return false;
6134 // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
6136 char* pName = strtok((char*)args, " ");
6137 if(!pName)
6138 return false;
6140 char* tail1 = strtok(NULL, "");
6141 if(!tail1)
6142 return false;
6144 char* msgSubject;
6145 if(*tail1=='"')
6146 msgSubject = strtok(tail1+1, "\"");
6147 else
6149 char* space = strtok(tail1, "\"");
6150 if(!space)
6151 return false;
6152 msgSubject = strtok(NULL, "\"");
6155 if (!msgSubject)
6156 return false;
6158 char* tail2 = strtok(NULL, "");
6159 if(!tail2)
6160 return false;
6162 char* msgText;
6163 if(*tail2=='"')
6164 msgText = strtok(tail2+1, "\"");
6165 else
6167 char* space = strtok(tail2, "\"");
6168 if(!space)
6169 return false;
6170 msgText = strtok(NULL, "\"");
6173 if (!msgText)
6174 return false;
6176 // pName, msgSubject, msgText isn't NUL after prev. check
6177 std::string name = pName;
6178 std::string subject = msgSubject;
6179 std::string text = msgText;
6181 // extract items
6182 typedef std::pair<uint32,uint32> ItemPair;
6183 typedef std::list< ItemPair > ItemPairs;
6184 ItemPairs items;
6186 // get all tail string
6187 char* tail = strtok(NULL, "");
6189 // get from tail next item str
6190 while(char* itemStr = strtok(tail, " "))
6192 // and get new tail
6193 tail = strtok(NULL, "");
6195 // parse item str
6196 char* itemIdStr = strtok(itemStr, ":");
6197 char* itemCountStr = strtok(NULL, " ");
6199 uint32 item_id = atoi(itemIdStr);
6200 if(!item_id)
6201 return false;
6203 ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
6204 if(!item_proto)
6206 PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
6207 SetSentErrorMessage(true);
6208 return false;
6211 uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
6212 if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
6214 PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
6215 SetSentErrorMessage(true);
6216 return false;
6219 while(item_count > item_proto->Stackable)
6221 items.push_back(ItemPair(item_id,item_proto->Stackable));
6222 item_count -= item_proto->Stackable;
6225 items.push_back(ItemPair(item_id,item_count));
6227 if(items.size() > MAX_MAIL_ITEMS)
6229 PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
6230 SetSentErrorMessage(true);
6231 return false;
6235 if(!normalizePlayerName(name))
6237 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6238 SetSentErrorMessage(true);
6239 return false;
6242 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6243 if(!receiver_guid)
6245 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6246 SetSentErrorMessage(true);
6247 return false;
6250 // from console show not existed sender
6251 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6253 uint32 messagetype = MAIL_NORMAL;
6254 uint32 stationery = MAIL_STATIONERY_GM;
6255 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6257 Player *receiver = objmgr.GetPlayer(receiver_guid);
6259 // fill mail
6260 MailItemsInfo mi; // item list preparing
6262 for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
6264 if(Item* item = Item::CreateItem(itr->first,itr->second,m_session ? m_session->GetPlayer() : 0))
6266 item->SaveToDB(); // save for prevent lost at next mail load, if send fail then item will deleted
6267 mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
6271 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
6273 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
6274 return true;
6277 ///Send money by mail
6278 bool ChatHandler::HandleSendMoneyCommand(const char* args)
6280 if (!*args)
6281 return false;
6283 /// format: name "subject text" "mail text" money
6285 char* pName = strtok((char*)args, " ");
6286 if (!pName)
6287 return false;
6289 char* tail1 = strtok(NULL, "");
6290 if (!tail1)
6291 return false;
6293 char* msgSubject;
6294 if (*tail1=='"')
6295 msgSubject = strtok(tail1+1, "\"");
6296 else
6298 char* space = strtok(tail1, "\"");
6299 if (!space)
6300 return false;
6301 msgSubject = strtok(NULL, "\"");
6304 if (!msgSubject)
6305 return false;
6307 char* tail2 = strtok(NULL, "");
6308 if (!tail2)
6309 return false;
6311 char* msgText;
6312 if (*tail2=='"')
6313 msgText = strtok(tail2+1, "\"");
6314 else
6316 char* space = strtok(tail2, "\"");
6317 if (!space)
6318 return false;
6319 msgText = strtok(NULL, "\"");
6322 if (!msgText)
6323 return false;
6325 int32 money = atoi(strtok(NULL, ""));
6326 if (money <= 0)
6327 return false;
6329 // pName, msgSubject, msgText isn't NUL after prev. check
6330 std::string name = pName;
6331 std::string subject = msgSubject;
6332 std::string text = msgText;
6334 if (!normalizePlayerName(name))
6336 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6337 SetSentErrorMessage(true);
6338 return false;
6341 uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
6342 if (!receiver_guid)
6344 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6345 SetSentErrorMessage(true);
6346 return false;
6349 uint32 mailId = objmgr.GenerateMailID();
6351 // from console show not existed sender
6352 uint32 sender_guidlo = m_session ? m_session->GetPlayer()->GetGUIDLow() : 0;
6354 uint32 messagetype = MAIL_NORMAL;
6355 uint32 stationery = MAIL_STATIONERY_GM;
6356 uint32 itemTextId = !text.empty() ? objmgr.CreateItemText( text ) : 0;
6358 Player *receiver = objmgr.GetPlayer(receiver_guid);
6360 WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, NULL, money, 0, MAIL_CHECK_MASK_NONE);
6362 PSendSysMessage(LANG_MAIL_SENT, name.c_str());
6363 return true;
6366 /// Send a message to a player in game
6367 bool ChatHandler::HandleSendMessageCommand(const char* args)
6369 ///- Get the command line arguments
6370 char* name_str = strtok((char*)args, " ");
6371 char* msg_str = strtok(NULL, "");
6373 if(!name_str || !msg_str)
6374 return false;
6376 std::string name = name_str;
6378 if(!normalizePlayerName(name))
6379 return false;
6381 ///- Find the player and check that he is not logging out.
6382 Player *rPlayer = objmgr.GetPlayer(name.c_str());
6383 if(!rPlayer)
6385 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6386 SetSentErrorMessage(true);
6387 return false;
6390 if(rPlayer->GetSession()->isLogingOut())
6392 SendSysMessage(LANG_PLAYER_NOT_FOUND);
6393 SetSentErrorMessage(true);
6394 return false;
6397 ///- Send the message
6398 //Use SendAreaTriggerMessage for fastest delivery.
6399 rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6400 rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6402 //Confirmation message
6403 PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6404 return true;
6407 bool ChatHandler::HandleModifyGenderCommand(const char *args)
6409 if(!*args)
6410 return false;
6412 Player *player = getSelectedPlayer();
6414 if(!player)
6416 PSendSysMessage(LANG_NO_PLAYER);
6417 SetSentErrorMessage(true);
6418 return false;
6421 char const* gender_str = (char*)args;
6422 int gender_len = strlen(gender_str);
6424 uint32 displayId = player->GetNativeDisplayId();
6425 char const* gender_full = NULL;
6426 uint32 new_displayId = displayId;
6427 Gender gender;
6429 if(!strncmp(gender_str,"male",gender_len)) // MALE
6431 if(player->getGender() == GENDER_MALE)
6432 return true;
6434 gender_full = "male";
6435 new_displayId = player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1;
6436 gender = GENDER_MALE;
6438 else if (!strncmp(gender_str,"female",gender_len)) // FEMALE
6440 if(player->getGender() == GENDER_FEMALE)
6441 return true;
6443 gender_full = "female";
6444 new_displayId = player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1;
6445 gender = GENDER_FEMALE;
6447 else
6449 SendSysMessage(LANG_MUST_MALE_OR_FEMALE);
6450 SetSentErrorMessage(true);
6451 return false;
6454 // Set gender
6455 player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender);
6457 // Change display ID
6458 player->SetDisplayId(new_displayId);
6459 player->SetNativeDisplayId(new_displayId);
6461 PSendSysMessage(LANG_YOU_CHANGE_GENDER, player->GetName(),gender_full);
6462 if (needReportToTarget(player))
6463 ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full,GetName());
6464 return true;