root/trunk/src/game/Level3.cpp @ 209

Revision 209, 182.2 kB (checked in by yumileroy, 17 years ago)

[svn] Fix some typos.

Original author: megamage
Date: 2008-11-10 17:19:35-06:00

Line 
1/*
2* Copyright (C) 2005-2008 MaNGOS <http://www.mangosproject.org/>
3*
4* Copyright (C) 2008 Trinity <http://www.trinitycore.org/>
5*
6* This program is free software; you can redistribute it and/or modify
7* it under the terms of the GNU General Public License as published by
8* the Free Software Foundation; either version 2 of the License, or
9* (at your option) any later version.
10*
11* This program is distributed in the hope that it will be useful,
12* but WITHOUT ANY WARRANTY; without even the implied warranty of
13* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14* GNU General Public License for more details.
15*
16* You should have received a copy of the GNU General Public License
17* along with this program; if not, write to the Free Software
18* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19*/
20
21#include "Common.h"
22#include "Database/DatabaseEnv.h"
23#include "WorldPacket.h"
24#include "WorldSession.h"
25#include "World.h"
26#include "ObjectMgr.h"
27#include "AccountMgr.h"
28#include "PlayerDump.h"
29#include "SpellMgr.h"
30#include "Player.h"
31#include "Opcodes.h"
32#include "GameObject.h"
33#include "Chat.h"
34#include "Log.h"
35#include "Guild.h"
36#include "ObjectAccessor.h"
37#include "MapManager.h"
38#include "SpellAuras.h"
39#include "ScriptCalls.h"
40#include "Language.h"
41#include "GridNotifiersImpl.h"
42#include "CellImpl.h"
43#include "Weather.h"
44#include "PointMovementGenerator.h"
45#include "TargetedMovementGenerator.h"
46#include "SkillDiscovery.h"
47#include "SkillExtraItems.h"
48#include "SystemConfig.h"
49#include "Config/ConfigEnv.h"
50#include "Util.h"
51#include "ItemEnchantmentMgr.h"
52#include "BattleGroundMgr.h"
53#include "InstanceSaveMgr.h"
54#include "InstanceData.h"
55#include "AccountMgr.h"
56
57//reload commands
58bool ChatHandler::HandleReloadCommand(const char* arg)
59{
60    // this is error catcher for wrong table name in .reload commands
61    PSendSysMessage("Db table with name starting from '%s' not found and can't be reloaded.",arg);
62    SetSentErrorMessage(true);
63    return false;
64}
65
66bool ChatHandler::HandleReloadAllCommand(const char*)
67{
68    HandleReloadAreaTriggerTeleportCommand("");
69    HandleReloadSkillFishingBaseLevelCommand("");
70
71    HandleReloadAllAreaCommand("");
72    HandleReloadAllLootCommand("");
73    HandleReloadAllNpcCommand("");
74    HandleReloadAllQuestCommand("");
75    HandleReloadAllSpellCommand("");
76    HandleReloadAllItemCommand("");
77    HandleReloadAllLocalesCommand("");
78
79    HandleReloadCommandCommand("");
80    HandleReloadReservedNameCommand("");
81    HandleReloadTrinityStringCommand("");
82    HandleReloadGameTeleCommand("");
83    return true;
84}
85
86bool ChatHandler::HandleReloadAllAreaCommand(const char*)
87{
88    //HandleReloadQuestAreaTriggersCommand(""); -- reloaded in HandleReloadAllQuestCommand
89    HandleReloadAreaTriggerTeleportCommand("");
90    HandleReloadAreaTriggerTavernCommand("");
91    HandleReloadGameGraveyardZoneCommand("");
92    return true;
93}
94
95bool ChatHandler::HandleReloadAllLootCommand(const char*)
96{
97    sLog.outString( "Re-Loading Loot Tables..." );
98    LoadLootTables();
99    SendGlobalSysMessage("DB tables `*_loot_template` reloaded.");
100    return true;
101}
102
103bool ChatHandler::HandleReloadAllNpcCommand(const char* /*args*/)
104{
105    HandleReloadNpcGossipCommand("a");
106    HandleReloadNpcOptionCommand("a");
107    HandleReloadNpcTrainerCommand("a");
108    HandleReloadNpcVendorCommand("a");
109    return true;
110}
111
112bool ChatHandler::HandleReloadAllQuestCommand(const char* /*args*/)
113{
114    HandleReloadQuestAreaTriggersCommand("a");
115    HandleReloadQuestTemplateCommand("a");
116
117    sLog.outString( "Re-Loading Quests Relations..." );
118    objmgr.LoadQuestRelations();
119    SendGlobalSysMessage("DB tables `*_questrelation` and `*_involvedrelation` reloaded.");
120    return true;
121}
122
123bool ChatHandler::HandleReloadAllScriptsCommand(const char*)
124{
125    if(sWorld.IsScriptScheduled())
126    {
127        PSendSysMessage("DB scripts used currently, please attempt reload later.");
128        SetSentErrorMessage(true);
129        return false;
130    }
131
132    sLog.outString( "Re-Loading Scripts..." );
133    HandleReloadGameObjectScriptsCommand("a");
134    HandleReloadEventScriptsCommand("a");
135    HandleReloadQuestEndScriptsCommand("a");
136    HandleReloadQuestStartScriptsCommand("a");
137    HandleReloadSpellScriptsCommand("a");
138    SendGlobalSysMessage("DB tables `*_scripts` reloaded.");
139    return true;
140}
141
142bool ChatHandler::HandleReloadAllSpellCommand(const char*)
143{
144    HandleReloadSkillDiscoveryTemplateCommand("a");
145    HandleReloadSkillExtraItemTemplateCommand("a");
146    HandleReloadSpellAffectCommand("a");
147    HandleReloadSpellChainCommand("a");
148    HandleReloadSpellElixirCommand("a");
149    HandleReloadSpellLearnSpellCommand("a");
150    HandleReloadSpellProcEventCommand("a");
151    HandleReloadSpellScriptTargetCommand("a");
152    HandleReloadSpellTargetPositionCommand("a");
153    HandleReloadSpellThreatsCommand("a");
154    HandleReloadSpellPetAurasCommand("a");
155    HandleReloadSpellDisabledCommand("a");
156    return true;
157}
158
159bool ChatHandler::HandleReloadAllItemCommand(const char*)
160{
161    HandleReloadPageTextsCommand("a");
162    HandleReloadItemEnchantementsCommand("a");
163    return true;
164}
165
166bool ChatHandler::HandleReloadAllLocalesCommand(const char* /*args*/)
167{
168    HandleReloadLocalesCreatureCommand("a");
169    HandleReloadLocalesGameobjectCommand("a");
170    HandleReloadLocalesItemCommand("a");
171    HandleReloadLocalesNpcTextCommand("a");
172    HandleReloadLocalesPageTextCommand("a");
173    HandleReloadLocalesQuestCommand("a");
174    return true;
175}
176
177bool ChatHandler::HandleReloadConfigCommand(const char* /*args*/)
178{
179    sLog.outString( "Re-Loading config settings..." );
180    sWorld.LoadConfigSettings(true);
181    SendGlobalSysMessage("World config settings reloaded.");
182    return true;
183}
184
185bool ChatHandler::HandleReloadAreaTriggerTavernCommand(const char*)
186{
187    sLog.outString( "Re-Loading Tavern Area Triggers..." );
188    objmgr.LoadTavernAreaTriggers();
189    SendGlobalSysMessage("DB table `areatrigger_tavern` reloaded.");
190    return true;
191}
192
193bool ChatHandler::HandleReloadAreaTriggerTeleportCommand(const char*)
194{
195    sLog.outString( "Re-Loading AreaTrigger teleport definitions..." );
196    objmgr.LoadAreaTriggerTeleports();
197    SendGlobalSysMessage("DB table `areatrigger_teleport` reloaded.");
198    return true;
199}
200
201bool ChatHandler::HandleReloadCommandCommand(const char*)
202{
203    load_command_table = true;
204    SendGlobalSysMessage("DB table `command` will be reloaded at next chat command use.");
205    return true;
206}
207
208bool ChatHandler::HandleReloadCreatureQuestRelationsCommand(const char*)
209{
210    sLog.outString( "Loading Quests Relations... (`creature_questrelation`)" );
211    objmgr.LoadCreatureQuestRelations();
212    SendGlobalSysMessage("DB table `creature_questrelation` (creature quest givers) reloaded.");
213    return true;
214}
215
216bool ChatHandler::HandleReloadCreatureQuestInvRelationsCommand(const char*)
217{
218    sLog.outString( "Loading Quests Relations... (`creature_involvedrelation`)" );
219    objmgr.LoadCreatureInvolvedRelations();
220    SendGlobalSysMessage("DB table `creature_involvedrelation` (creature quest takers) reloaded.");
221    return true;
222}
223
224bool ChatHandler::HandleReloadGOQuestRelationsCommand(const char*)
225{
226    sLog.outString( "Loading Quests Relations... (`gameobject_questrelation`)" );
227    objmgr.LoadGameobjectQuestRelations();
228    SendGlobalSysMessage("DB table `gameobject_questrelation` (gameobject quest givers) reloaded.");
229    return true;
230}
231
232bool ChatHandler::HandleReloadGOQuestInvRelationsCommand(const char*)
233{
234    sLog.outString( "Loading Quests Relations... (`gameobject_involvedrelation`)" );
235    objmgr.LoadGameobjectInvolvedRelations();
236    SendGlobalSysMessage("DB table `gameobject_involvedrelation` (gameobject quest takers) reloaded.");
237    return true;
238}
239
240bool ChatHandler::HandleReloadQuestAreaTriggersCommand(const char*)
241{
242    sLog.outString( "Re-Loading Quest Area Triggers..." );
243    objmgr.LoadQuestAreaTriggers();
244    SendGlobalSysMessage("DB table `areatrigger_involvedrelation` (quest area triggers) reloaded.");
245    return true;
246}
247
248bool ChatHandler::HandleReloadQuestTemplateCommand(const char*)
249{
250    sLog.outString( "Re-Loading Quest Templates..." );
251    objmgr.LoadQuests();
252    SendGlobalSysMessage("DB table `quest_template` (quest definitions) reloaded.");
253    return true;
254}
255
256bool ChatHandler::HandleReloadLootTemplatesCreatureCommand(const char*)
257{
258    sLog.outString( "Re-Loading Loot Tables... (`creature_loot_template`)" );
259    LoadLootTemplates_Creature();
260    LootTemplates_Creature.CheckLootRefs();
261    SendGlobalSysMessage("DB table `creature_loot_template` reloaded.");
262    return true;
263}
264
265bool ChatHandler::HandleReloadLootTemplatesDisenchantCommand(const char*)
266{
267    sLog.outString( "Re-Loading Loot Tables... (`disenchant_loot_template`)" );
268    LoadLootTemplates_Disenchant();
269    LootTemplates_Disenchant.CheckLootRefs();
270    SendGlobalSysMessage("DB table `disenchant_loot_template` reloaded.");
271    return true;
272}
273
274bool ChatHandler::HandleReloadLootTemplatesFishingCommand(const char*)
275{
276    sLog.outString( "Re-Loading Loot Tables... (`fishing_loot_template`)" );
277    LoadLootTemplates_Fishing();
278    LootTemplates_Fishing.CheckLootRefs();
279    SendGlobalSysMessage("DB table `fishing_loot_template` reloaded.");
280    return true;
281}
282
283bool ChatHandler::HandleReloadLootTemplatesGameobjectCommand(const char*)
284{
285    sLog.outString( "Re-Loading Loot Tables... (`gameobject_loot_template`)" );
286    LoadLootTemplates_Gameobject();
287    LootTemplates_Gameobject.CheckLootRefs();
288    SendGlobalSysMessage("DB table `gameobject_loot_template` reloaded.");
289    return true;
290}
291
292bool ChatHandler::HandleReloadLootTemplatesItemCommand(const char*)
293{
294    sLog.outString( "Re-Loading Loot Tables... (`item_loot_template`)" );
295    LoadLootTemplates_Item();
296    LootTemplates_Item.CheckLootRefs();
297    SendGlobalSysMessage("DB table `item_loot_template` reloaded.");
298    return true;
299}
300
301bool ChatHandler::HandleReloadLootTemplatesPickpocketingCommand(const char*)
302{
303    sLog.outString( "Re-Loading Loot Tables... (`pickpocketing_loot_template`)" );
304    LoadLootTemplates_Pickpocketing();
305    LootTemplates_Pickpocketing.CheckLootRefs();
306    SendGlobalSysMessage("DB table `pickpocketing_loot_template` reloaded.");
307    return true;
308}
309
310bool ChatHandler::HandleReloadLootTemplatesProspectingCommand(const char*)
311{
312    sLog.outString( "Re-Loading Loot Tables... (`prospecting_loot_template`)" );
313    LoadLootTemplates_Prospecting();
314    LootTemplates_Prospecting.CheckLootRefs();
315    SendGlobalSysMessage("DB table `prospecting_loot_template` reloaded.");
316    return true;
317}
318
319bool ChatHandler::HandleReloadLootTemplatesQuestMailCommand(const char*)
320{
321    sLog.outString( "Re-Loading Loot Tables... (`quest_mail_loot_template`)" );
322    LoadLootTemplates_QuestMail();
323    LootTemplates_QuestMail.CheckLootRefs();
324    SendGlobalSysMessage("DB table `quest_mail_loot_template` reloaded.");
325    return true;
326}
327
328bool ChatHandler::HandleReloadLootTemplatesReferenceCommand(const char*)
329{
330    sLog.outString( "Re-Loading Loot Tables... (`reference_loot_template`)" );
331    LoadLootTemplates_Reference();
332    SendGlobalSysMessage("DB table `reference_loot_template` reloaded.");
333    return true;
334}
335
336bool ChatHandler::HandleReloadLootTemplatesSkinningCommand(const char*)
337{
338    sLog.outString( "Re-Loading Loot Tables... (`skinning_loot_template`)" );
339    LoadLootTemplates_Skinning();
340    LootTemplates_Skinning.CheckLootRefs();
341    SendGlobalSysMessage("DB table `skinning_loot_template` reloaded.");
342    return true;
343}
344
345bool ChatHandler::HandleReloadTrinityStringCommand(const char*)
346{
347    sLog.outString( "Re-Loading trinity_string Table!" );
348    objmgr.LoadTrinityStrings();
349    SendGlobalSysMessage("DB table `trinity_string` reloaded.");
350    return true;
351}
352
353bool ChatHandler::HandleReloadNpcOptionCommand(const char*)
354{
355    sLog.outString( "Re-Loading `npc_option` Table!" );
356    objmgr.LoadNpcOptions();
357    SendGlobalSysMessage("DB table `npc_option` reloaded.");
358    return true;
359}
360
361bool ChatHandler::HandleReloadNpcGossipCommand(const char*)
362{
363    sLog.outString( "Re-Loading `npc_gossip` Table!" );
364    objmgr.LoadNpcTextId();
365    SendGlobalSysMessage("DB table `npc_gossip` reloaded.");
366    return true;
367}
368
369bool ChatHandler::HandleReloadNpcTrainerCommand(const char*)
370{
371    sLog.outString( "Re-Loading `npc_trainer` Table!" );
372    objmgr.LoadTrainerSpell();
373    SendGlobalSysMessage("DB table `npc_trainer` reloaded.");
374    return true;
375}
376
377bool ChatHandler::HandleReloadNpcVendorCommand(const char*)
378{
379    sLog.outString( "Re-Loading `npc_vendor` Table!" );
380    objmgr.LoadVendors();
381    SendGlobalSysMessage("DB table `npc_vendor` reloaded.");
382    return true;
383}
384
385bool ChatHandler::HandleReloadReservedNameCommand(const char*)
386{
387    sLog.outString( "Loading ReservedNames... (`reserved_name`)" );
388    objmgr.LoadReservedPlayersNames();
389    SendGlobalSysMessage("DB table `reserved_name` (player reserved names) reloaded.");
390    return true;
391}
392
393bool ChatHandler::HandleReloadSkillDiscoveryTemplateCommand(const char* /*args*/)
394{
395    sLog.outString( "Re-Loading Skill Discovery Table..." );
396    LoadSkillDiscoveryTable();
397    SendGlobalSysMessage("DB table `skill_discovery_template` (recipes discovered at crafting) reloaded.");
398    return true;
399}
400
401bool ChatHandler::HandleReloadSkillExtraItemTemplateCommand(const char* /*args*/)
402{
403    sLog.outString( "Re-Loading Skill Extra Item Table..." );
404    LoadSkillExtraItemTable();
405    SendGlobalSysMessage("DB table `skill_extra_item_template` (extra item creation when crafting) reloaded.");
406    return true;
407}
408
409bool ChatHandler::HandleReloadSkillFishingBaseLevelCommand(const char* /*args*/)
410{
411    sLog.outString( "Re-Loading Skill Fishing base level requirements..." );
412    objmgr.LoadFishingBaseSkillLevel();
413    SendGlobalSysMessage("DB table `skill_fishing_base_level` (fishing base level for zone/subzone) reloaded.");
414    return true;
415}
416
417bool ChatHandler::HandleReloadSpellAffectCommand(const char*)
418{
419    sLog.outString( "Re-Loading SpellAffect definitions..." );
420    spellmgr.LoadSpellAffects();
421    SendGlobalSysMessage("DB table `spell_affect` (spell mods apply requirements) reloaded.");
422    return true;
423}
424
425bool ChatHandler::HandleReloadSpellChainCommand(const char*)
426{
427    sLog.outString( "Re-Loading Spell Chain Data... " );
428    spellmgr.LoadSpellChains();
429    SendGlobalSysMessage("DB table `spell_chain` (spell ranks) reloaded.");
430    return true;
431}
432
433bool ChatHandler::HandleReloadSpellElixirCommand(const char*)
434{
435    sLog.outString( "Re-Loading Spell Elixir types..." );
436    spellmgr.LoadSpellElixirs();
437    SendGlobalSysMessage("DB table `spell_elixir` (spell elixir types) reloaded.");
438    return true;
439}
440
441bool ChatHandler::HandleReloadSpellLearnSpellCommand(const char*)
442{
443    sLog.outString( "Re-Loading Spell Learn Spells..." );
444    spellmgr.LoadSpellLearnSpells();
445    SendGlobalSysMessage("DB table `spell_learn_spell` reloaded.");
446    return true;
447}
448
449bool ChatHandler::HandleReloadSpellProcEventCommand(const char*)
450{
451    sLog.outString( "Re-Loading Spell Proc Event conditions..." );
452    spellmgr.LoadSpellProcEvents();
453    SendGlobalSysMessage("DB table `spell_proc_event` (spell proc trigger requirements) reloaded.");
454    return true;
455}
456
457bool ChatHandler::HandleReloadSpellScriptTargetCommand(const char*)
458{
459    sLog.outString( "Re-Loading SpellsScriptTarget..." );
460    spellmgr.LoadSpellScriptTarget();
461    SendGlobalSysMessage("DB table `spell_script_target` (spell targets selection in case specific creature/GO requirements) reloaded.");
462    return true;
463}
464
465bool ChatHandler::HandleReloadSpellTargetPositionCommand(const char*)
466{
467    sLog.outString( "Re-Loading Spell target coordinates..." );
468    spellmgr.LoadSpellTargetPositions();
469    SendGlobalSysMessage("DB table `spell_target_position` (destination coordinates for spell targets) reloaded.");
470    return true;
471}
472
473bool ChatHandler::HandleReloadSpellThreatsCommand(const char*)
474{
475    sLog.outString( "Re-Loading Aggro Spells Definitions...");
476    spellmgr.LoadSpellThreats();
477    SendGlobalSysMessage("DB table `spell_threat` (spell aggro definitions) reloaded.");
478    return true;
479}
480
481bool ChatHandler::HandleReloadSpellPetAurasCommand(const char*)
482{
483    sLog.outString( "Re-Loading Spell pet auras...");
484    spellmgr.LoadSpellPetAuras();
485    SendGlobalSysMessage("DB table `spell_pet_auras` reloaded.");
486    return true;
487}
488
489bool ChatHandler::HandleReloadPageTextsCommand(const char*)
490{
491    sLog.outString( "Re-Loading Page Texts..." );
492    objmgr.LoadPageTexts();
493    SendGlobalSysMessage("DB table `page_texts` reloaded.");
494    return true;
495}
496
497bool ChatHandler::HandleReloadItemEnchantementsCommand(const char*)
498{
499    sLog.outString( "Re-Loading Item Random Enchantments Table..." );
500    LoadRandomEnchantmentsTable();
501    SendGlobalSysMessage("DB table `item_enchantment_template` reloaded.");
502    return true;
503}
504
505bool ChatHandler::HandleReloadGameObjectScriptsCommand(const char* arg)
506{
507    if(sWorld.IsScriptScheduled())
508    {
509        SendSysMessage("DB scripts used currently, please attempt reload later.");
510        SetSentErrorMessage(true);
511        return false;
512    }
513
514    if(*arg!='a')
515        sLog.outString( "Re-Loading Scripts from `gameobject_scripts`...");
516
517    objmgr.LoadGameObjectScripts();
518
519    if(*arg!='a')
520        SendGlobalSysMessage("DB table `gameobject_scripts` reloaded.");
521
522    return true;
523}
524
525bool ChatHandler::HandleReloadEventScriptsCommand(const char* arg)
526{
527    if(sWorld.IsScriptScheduled())
528    {
529        SendSysMessage("DB scripts used currently, please attempt reload later.");
530        SetSentErrorMessage(true);
531        return false;
532    }
533
534    if(*arg!='a')
535        sLog.outString( "Re-Loading Scripts from `event_scripts`...");
536
537    objmgr.LoadEventScripts();
538
539    if(*arg!='a')
540        SendGlobalSysMessage("DB table `event_scripts` reloaded.");
541
542    return true;
543}
544
545bool ChatHandler::HandleReloadQuestEndScriptsCommand(const char* arg)
546{
547    if(sWorld.IsScriptScheduled())
548    {
549        SendSysMessage("DB scripts used currently, please attempt reload later.");
550        SetSentErrorMessage(true);
551        return false;
552    }
553
554    if(*arg!='a')
555        sLog.outString( "Re-Loading Scripts from `quest_end_scripts`...");
556
557    objmgr.LoadQuestEndScripts();
558
559    if(*arg!='a')
560        SendGlobalSysMessage("DB table `quest_end_scripts` reloaded.");
561
562    return true;
563}
564
565bool ChatHandler::HandleReloadQuestStartScriptsCommand(const char* arg)
566{
567    if(sWorld.IsScriptScheduled())
568    {
569        SendSysMessage("DB scripts used currently, please attempt reload later.");
570        SetSentErrorMessage(true);
571        return false;
572    }
573
574    if(*arg!='a')
575        sLog.outString( "Re-Loading Scripts from `quest_start_scripts`...");
576
577    objmgr.LoadQuestStartScripts();
578
579    if(*arg!='a')
580        SendGlobalSysMessage("DB table `quest_start_scripts` reloaded.");
581
582    return true;
583}
584
585bool ChatHandler::HandleReloadSpellScriptsCommand(const char* arg)
586{
587    if(sWorld.IsScriptScheduled())
588    {
589        SendSysMessage("DB scripts used currently, please attempt reload later.");
590        SetSentErrorMessage(true);
591        return false;
592    }
593
594    if(*arg!='a')
595        sLog.outString( "Re-Loading Scripts from `spell_scripts`...");
596
597    objmgr.LoadSpellScripts();
598
599    if(*arg!='a')
600        SendGlobalSysMessage("DB table `spell_scripts` reloaded.");
601
602    return true;
603}
604
605bool ChatHandler::HandleReloadGameGraveyardZoneCommand(const char* /*arg*/)
606{
607    sLog.outString( "Re-Loading Graveyard-zone links...");
608
609    objmgr.LoadGraveyardZones();
610
611    SendGlobalSysMessage("DB table `game_graveyard_zone` reloaded.");
612
613    return true;
614}
615
616bool ChatHandler::HandleReloadGameTeleCommand(const char* /*arg*/)
617{
618    sLog.outString( "Re-Loading Game Tele coordinates...");
619
620    objmgr.LoadGameTele();
621
622    SendGlobalSysMessage("DB table `game_tele` reloaded.");
623
624    return true;
625}
626
627bool ChatHandler::HandleReloadSpellDisabledCommand(const char* /*arg*/)
628{
629    sLog.outString( "Re-Loading spell disabled table...");
630
631    objmgr.LoadSpellDisabledEntrys();
632
633    SendGlobalSysMessage("DB table `spell_disabled` reloaded.");
634
635    return true;
636}
637
638bool ChatHandler::HandleReloadLocalesCreatureCommand(const char* /*arg*/)
639{
640    sLog.outString( "Re-Loading Locales Creature ...");
641    objmgr.LoadCreatureLocales();
642    SendGlobalSysMessage("DB table `locales_creature` reloaded.");
643    return true;
644}
645
646bool ChatHandler::HandleReloadLocalesGameobjectCommand(const char* /*arg*/)
647{
648    sLog.outString( "Re-Loading Locales Gameobject ... ");
649    objmgr.LoadGameObjectLocales();
650    SendGlobalSysMessage("DB table `locales_gameobject` reloaded.");
651    return true;
652}
653
654bool ChatHandler::HandleReloadLocalesItemCommand(const char* /*arg*/)
655{
656    sLog.outString( "Re-Loading Locales Item ... ");
657    objmgr.LoadItemLocales();
658    SendGlobalSysMessage("DB table `locales_item` reloaded.");
659    return true;
660}
661
662bool ChatHandler::HandleReloadLocalesNpcTextCommand(const char* /*arg*/)
663{
664    sLog.outString( "Re-Loading Locales NPC Text ... ");
665    objmgr.LoadNpcTextLocales();
666    SendGlobalSysMessage("DB table `locales_npc_text` reloaded.");
667    return true;
668}
669
670bool ChatHandler::HandleReloadLocalesPageTextCommand(const char* /*arg*/)
671{
672    sLog.outString( "Re-Loading Locales Page Text ... ");
673    objmgr.LoadPageTextLocales();
674    SendGlobalSysMessage("DB table `locales_page_text` reloaded.");
675    return true;
676}
677
678bool ChatHandler::HandleReloadLocalesQuestCommand(const char* /*arg*/)
679{
680    sLog.outString( "Re-Loading Locales Quest ... ");
681    objmgr.LoadQuestLocales();
682    SendGlobalSysMessage("DB table `locales_quest` reloaded.");
683    return true;
684}
685
686bool ChatHandler::HandleLoadScriptsCommand(const char* args)
687{
688    if(!LoadScriptingModule(args)) return true;
689
690    sWorld.SendWorldText(LANG_SCRIPTS_RELOADED);
691    return true;
692}
693
694bool ChatHandler::HandleAccountSetGmLevelCommand(const char* args)
695{
696    char* arg1 = strtok((char*)args, " ");
697    if( !arg1 )
698        return false;
699
700    /// must be NULL if targeted syntax and must be not nULL if not targeted
701    char* arg2 = strtok(NULL, " ");
702
703    std::string targetAccountName;
704    uint32 targetAccountId = 0;
705    uint32 targetSecurity = 0;
706
707    /// only target player different from self allowed (if targetPlayer!=NULL then not console)
708    Player* targetPlayer = getSelectedPlayer();
709    if(targetPlayer && m_session->GetPlayer()!=targetPlayer)
710    {
711        /// wrong command syntax or unexpected targeting
712        if(arg2)
713            return false;
714
715        /// security level expected in arg2 after this if.
716        arg2 = arg1;
717
718        targetAccountId = targetPlayer->GetSession()->GetAccountId();
719        targetSecurity = targetPlayer->GetSession()->GetSecurity();
720        if(!accmgr.GetName(targetAccountId,targetAccountName))
721        {
722            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
723            SetSentErrorMessage(true);
724            return false;
725        }
726    }
727    else
728    {
729        /// wrong command syntax (second arg expected)
730        if(!arg2)
731            return false;
732
733        targetAccountName = arg1;
734        if(!AccountMgr::normilizeString(targetAccountName))
735        {
736            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,targetAccountName.c_str());
737            SetSentErrorMessage(true);
738            return false;
739        }
740
741        targetAccountId = accmgr.GetId(targetAccountName);
742        targetSecurity = accmgr.GetSecurity(targetAccountId);
743    }
744
745    int32 gm = (int32)atoi(arg2);
746    if ( gm < SEC_PLAYER || gm > SEC_ADMINISTRATOR )
747    {
748        SendSysMessage(LANG_BAD_VALUE);
749        SetSentErrorMessage(true);
750        return false;
751    }
752
753    /// m_session==NULL only for console
754    uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
755
756    /// can set security level only for target with less security and to less security that we have
757    /// This is also reject self apply in fact
758    if(targetSecurity >= plSecurity || uint32(gm) >= plSecurity )
759    {
760        SendSysMessage(LANG_YOURS_SECURITY_IS_LOW);
761        SetSentErrorMessage(true);
762        return false;
763    }
764
765    if(targetPlayer)
766    {
767        ChatHandler(targetPlayer).PSendSysMessage(LANG_YOURS_SECURITY_CHANGED,GetName(), gm);
768        targetPlayer->GetSession()->SetSecurity(gm);
769    }
770
771    PSendSysMessage(LANG_YOU_CHANGE_SECURITY, targetAccountName.c_str(), gm);
772    loginDatabase.PExecute("UPDATE account SET gmlevel = '%i' WHERE id = '%u'", gm, targetAccountId);
773
774    return true;
775}
776
777/// Set password for account
778bool ChatHandler::HandleAccountSetPasswordCommand(const char* args)
779{
780    if(!*args)
781        return false;
782
783    ///- Get the command line arguments
784    char *szAccount = strtok ((char*)args," ");
785    char *szPassword1 =  strtok (NULL," ");
786    char *szPassword2 =  strtok (NULL," ");
787
788    if (!szAccount||!szPassword1 || !szPassword2)
789        return false;
790
791    std::string account_name = szAccount;
792    if(!AccountMgr::normilizeString(account_name))
793    {
794        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
795        SetSentErrorMessage(true);
796        return false;
797    }
798
799    uint32 targetAccountId = accmgr.GetId(account_name);
800    if (!targetAccountId)
801    {
802        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
803        SetSentErrorMessage(true);
804        return false;
805    }
806
807    uint32 targetSecurity = accmgr.GetSecurity(targetAccountId);
808
809    /// m_session==NULL only for console
810    uint32 plSecurity = m_session ? m_session->GetSecurity() : SEC_CONSOLE;
811
812    /// can set password only for target with less security
813    /// This is also reject self apply in fact
814    if (targetSecurity >= plSecurity)
815    {
816        SendSysMessage (LANG_YOURS_SECURITY_IS_LOW);
817        SetSentErrorMessage (true);
818        return false;
819    }
820
821    if (strcmp(szPassword1,szPassword2))
822    {
823        SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
824        SetSentErrorMessage (true);
825        return false;
826    }
827
828    AccountOpResult result = accmgr.ChangePassword(targetAccountId, szPassword1);
829
830    switch(result)
831    {
832        case AOR_OK:
833            SendSysMessage(LANG_COMMAND_PASSWORD);
834            break;
835        case AOR_NAME_NOT_EXIST:
836            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
837            SetSentErrorMessage(true);
838            return false;
839        case AOR_PASS_TOO_LONG:
840            SendSysMessage(LANG_PASSWORD_TOO_LONG);
841            SetSentErrorMessage(true);
842            return false;
843        default:
844            SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
845            SetSentErrorMessage(true);
846            return false;
847    }
848
849    return true;
850}
851
852bool ChatHandler::HandleAllowMovementCommand(const char* /*args*/)
853{
854    if(sWorld.getAllowMovement())
855    {
856        sWorld.SetAllowMovement(false);
857        SendSysMessage(LANG_CREATURE_MOVE_DISABLED);
858    }
859    else
860    {
861        sWorld.SetAllowMovement(true);
862        SendSysMessage(LANG_CREATURE_MOVE_ENABLED);
863    }
864    return true;
865}
866
867bool ChatHandler::HandleMaxSkillCommand(const char* /*args*/)
868{
869    Player* SelectedPlayer = getSelectedPlayer();
870    if(!SelectedPlayer)
871    {
872        SendSysMessage(LANG_NO_CHAR_SELECTED);
873        SetSentErrorMessage(true);
874        return false;
875    }
876
877    // each skills that have max skill value dependent from level seted to current level max skill value
878    SelectedPlayer->UpdateSkillsToMaxSkillsForLevel();
879    return true;
880}
881
882bool ChatHandler::HandleSetSkillCommand(const char* args)
883{
884    // number or [name] Shift-click form |color|Hskill:skill_id|h[name]|h|r
885    char* skill_p = extractKeyFromLink((char*)args,"Hskill");
886    if(!skill_p)
887        return false;
888
889    char *level_p = strtok (NULL, " ");
890
891    if( !level_p)
892        return false;
893
894    char *max_p   = strtok (NULL, " ");
895
896    int32 skill = atoi(skill_p);
897
898    if (skill <= 0)
899    {
900        PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
901        SetSentErrorMessage(true);
902        return false;
903    }
904
905    int32 level = atol (level_p);
906
907    Player * target = getSelectedPlayer();
908    if(!target)
909    {
910        SendSysMessage(LANG_NO_CHAR_SELECTED);
911        SetSentErrorMessage(true);
912        return false;
913    }
914
915    SkillLineEntry const* sl = sSkillLineStore.LookupEntry(skill);
916    if(!sl)
917    {
918        PSendSysMessage(LANG_INVALID_SKILL_ID, skill);
919        SetSentErrorMessage(true);
920        return false;
921    }
922
923    if(!target->GetSkillValue(skill))
924    {
925        PSendSysMessage(LANG_SET_SKILL_ERROR, target->GetName(), skill, sl->name[0]);
926        SetSentErrorMessage(true);
927        return false;
928    }
929
930    int32 max   = max_p ? atol (max_p) : target->GetPureMaxSkillValue(skill);
931
932    if( level <= 0 || level > max || max <= 0 )
933        return false;
934
935    target->SetSkill(skill, level, max);
936    PSendSysMessage(LANG_SET_SKILL, skill, sl->name[0], target->GetName(), level, max);
937
938    return true;
939}
940
941bool ChatHandler::HandleUnLearnCommand(const char* args)
942{
943    if (!*args)
944        return false;
945
946    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
947    uint32 min_id = extractSpellIdFromLink((char*)args);
948    if(!min_id)
949        return false;
950
951    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
952    char* tail = strtok(NULL,"");
953
954    uint32 max_id = extractSpellIdFromLink(tail);
955
956    if (!max_id)
957    {
958        // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
959        max_id =  min_id+1;
960    }
961    else
962    {
963        if (max_id < min_id)
964            std::swap(min_id,max_id);
965
966        max_id=max_id+1;
967    }
968
969    Player* target = getSelectedPlayer();
970    if(!target)
971    {
972        SendSysMessage(LANG_NO_CHAR_SELECTED);
973        SetSentErrorMessage(true);
974        return false;
975    }
976
977    for(uint32 spell=min_id;spell<max_id;spell++)
978    {
979        if (target->HasSpell(spell))
980            target->removeSpell(spell);
981        else
982            SendSysMessage(LANG_FORGET_SPELL);
983    }
984
985    return true;
986}
987
988bool ChatHandler::HandleCooldownCommand(const char* args)
989{
990    Player* target = getSelectedPlayer();
991    if(!target)
992    {
993        SendSysMessage(LANG_PLAYER_NOT_FOUND);
994        SetSentErrorMessage(true);
995        return false;
996    }
997
998    if (!*args)
999    {
1000        target->RemoveAllSpellCooldown();
1001        PSendSysMessage(LANG_REMOVEALL_COOLDOWN, target->GetName());
1002    }
1003    else
1004    {
1005        // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1006        uint32 spell_id = extractSpellIdFromLink((char*)args);
1007        if(!spell_id)
1008            return false;
1009
1010        if(!sSpellStore.LookupEntry(spell_id))
1011        {
1012            PSendSysMessage(LANG_UNKNOWN_SPELL, target==m_session->GetPlayer() ? GetTrinityString(LANG_YOU) : target->GetName());
1013            SetSentErrorMessage(true);
1014            return false;
1015        }
1016
1017        WorldPacket data( SMSG_CLEAR_COOLDOWN, (4+8) );
1018        data << uint32(spell_id);
1019        data << uint64(target->GetGUID());
1020        target->GetSession()->SendPacket(&data);
1021        target->RemoveSpellCooldown(spell_id);
1022        PSendSysMessage(LANG_REMOVE_COOLDOWN, spell_id, target==m_session->GetPlayer() ? GetTrinityString(LANG_YOU) : target->GetName());
1023    }
1024    return true;
1025}
1026
1027bool ChatHandler::HandleLearnAllCommand(const char* /*args*/)
1028{
1029    static const char *allSpellList[] =
1030    {
1031        "3365",
1032        "6233",
1033        "6247",
1034        "6246",
1035        "6477",
1036        "6478",
1037        "22810",
1038        "8386",
1039        "21651",
1040        "21652",
1041        "522",
1042        "7266",
1043        "8597",
1044        "2479",
1045        "22027",
1046        "6603",
1047        "5019",
1048        "133",
1049        "168",
1050        "227",
1051        "5009",
1052        "9078",
1053        "668",
1054        "203",
1055        "20599",
1056        "20600",
1057        "81",
1058        "20597",
1059        "20598",
1060        "20864",
1061        "1459",
1062        "5504",
1063        "587",
1064        "5143",
1065        "118",
1066        "5505",
1067        "597",
1068        "604",
1069        "1449",
1070        "1460",
1071        "2855",
1072        "1008",
1073        "475",
1074        "5506",
1075        "1463",
1076        "12824",
1077        "8437",
1078        "990",
1079        "5145",
1080        "8450",
1081        "1461",
1082        "759",
1083        "8494",
1084        "8455",
1085        "8438",
1086        "6127",
1087        "8416",
1088        "6129",
1089        "8451",
1090        "8495",
1091        "8439",
1092        "3552",
1093        "8417",
1094        "10138",
1095        "12825",
1096        "10169",
1097        "10156",
1098        "10144",
1099        "10191",
1100        "10201",
1101        "10211",
1102        "10053",
1103        "10173",
1104        "10139",
1105        "10145",
1106        "10192",
1107        "10170",
1108        "10202",
1109        "10054",
1110        "10174",
1111        "10193",
1112        "12826",
1113        "2136",
1114        "143",
1115        "145",
1116        "2137",
1117        "2120",
1118        "3140",
1119        "543",
1120        "2138",
1121        "2948",
1122        "8400",
1123        "2121",
1124        "8444",
1125        "8412",
1126        "8457",
1127        "8401",
1128        "8422",
1129        "8445",
1130        "8402",
1131        "8413",
1132        "8458",
1133        "8423",
1134        "8446",
1135        "10148",
1136        "10197",
1137        "10205",
1138        "10149",
1139        "10215",
1140        "10223",
1141        "10206",
1142        "10199",
1143        "10150",
1144        "10216",
1145        "10207",
1146        "10225",
1147        "10151",
1148        "116",
1149        "205",
1150        "7300",
1151        "122",
1152        "837",
1153        "10",
1154        "7301",
1155        "7322",
1156        "6143",
1157        "120",
1158        "865",
1159        "8406",
1160        "6141",
1161        "7302",
1162        "8461",
1163        "8407",
1164        "8492",
1165        "8427",
1166        "8408",
1167        "6131",
1168        "7320",
1169        "10159",
1170        "8462",
1171        "10185",
1172        "10179",
1173        "10160",
1174        "10180",
1175        "10219",
1176        "10186",
1177        "10177",
1178        "10230",
1179        "10181",
1180        "10161",
1181        "10187",
1182        "10220",
1183        "2018",
1184        "2663",
1185        "12260",
1186        "2660",
1187        "3115",
1188        "3326",
1189        "2665",
1190        "3116",
1191        "2738",
1192        "3293",
1193        "2661",
1194        "3319",
1195        "2662",
1196        "9983",
1197        "8880",
1198        "2737",
1199        "2739",
1200        "7408",
1201        "3320",
1202        "2666",
1203        "3323",
1204        "3324",
1205        "3294",
1206        "22723",
1207        "23219",
1208        "23220",
1209        "23221",
1210        "23228",
1211        "23338",
1212        "10788",
1213        "10790",
1214        "5611",
1215        "5016",
1216        "5609",
1217        "2060",
1218        "10963",
1219        "10964",
1220        "10965",
1221        "22593",
1222        "22594",
1223        "596",
1224        "996",
1225        "499",
1226        "768",
1227        "17002",
1228        "1448",
1229        "1082",
1230        "16979",
1231        "1079",
1232        "5215",
1233        "20484",
1234        "5221",
1235        "15590",
1236        "17007",
1237        "6795",
1238        "6807",
1239        "5487",
1240        "1446",
1241        "1066",
1242        "5421",
1243        "3139",
1244        "779",
1245        "6811",
1246        "6808",
1247        "1445",
1248        "5216",
1249        "1737",
1250        "5222",
1251        "5217",
1252        "1432",
1253        "6812",
1254        "9492",
1255        "5210",
1256        "3030",
1257        "1441",
1258        "783",
1259        "6801",
1260        "20739",
1261        "8944",
1262        "9491",
1263        "22569",
1264        "5226",
1265        "6786",
1266        "1433",
1267        "8973",
1268        "1828",
1269        "9495",
1270        "9006",
1271        "6794",
1272        "8993",
1273        "5203",
1274        "16914",
1275        "6784",
1276        "9635",
1277        "22830",
1278        "20722",
1279        "9748",
1280        "6790",
1281        "9753",
1282        "9493",
1283        "9752",
1284        "9831",
1285        "9825",
1286        "9822",
1287        "5204",
1288        "5401",
1289        "22831",
1290        "6793",
1291        "9845",
1292        "17401",
1293        "9882",
1294        "9868",
1295        "20749",
1296        "9893",
1297        "9899",
1298        "9895",
1299        "9832",
1300        "9902",
1301        "9909",
1302        "22832",
1303        "9828",
1304        "9851",
1305        "9883",
1306        "9869",
1307        "17406",
1308        "17402",
1309        "9914",
1310        "20750",
1311        "9897",
1312        "9848",
1313        "3127",
1314        "107",
1315        "204",
1316        "9116",
1317        "2457",
1318        "78",
1319        "18848",
1320        "331",
1321        "403",
1322        "2098",
1323        "1752",
1324        "11278",
1325        "11288",
1326        "11284",
1327        "6461",
1328        "2344",
1329        "2345",
1330        "6463",
1331        "2346",
1332        "2352",
1333        "775",
1334        "1434",
1335        "1612",
1336        "71",
1337        "2468",
1338        "2458",
1339        "2467",
1340        "7164",
1341        "7178",
1342        "7367",
1343        "7376",
1344        "7381",
1345        "21156",
1346        "5209",
1347        "3029",
1348        "5201",
1349        "9849",
1350        "9850",
1351        "20719",
1352        "22568",
1353        "22827",
1354        "22828",
1355        "22829",
1356        "6809",
1357        "8972",
1358        "9005",
1359        "9823",
1360        "9827",
1361        "6783",
1362        "9913",
1363        "6785",
1364        "6787",
1365        "9866",
1366        "9867",
1367        "9894",
1368        "9896",
1369        "6800",
1370        "8992",
1371        "9829",
1372        "9830",
1373        "780",
1374        "769",
1375        "6749",
1376        "6750",
1377        "9755",
1378        "9754",
1379        "9908",
1380        "20745",
1381        "20742",
1382        "20747",
1383        "20748",
1384        "9746",
1385        "9745",
1386        "9880",
1387        "9881",
1388        "5391",
1389        "842",
1390        "3025",
1391        "3031",
1392        "3287",
1393        "3329",
1394        "1945",
1395        "3559",
1396        "4933",
1397        "4934",
1398        "4935",
1399        "4936",
1400        "5142",
1401        "5390",
1402        "5392",
1403        "5404",
1404        "5420",
1405        "6405",
1406        "7293",
1407        "7965",
1408        "8041",
1409        "8153",
1410        "9033",
1411        "9034",
1412        //"9036", problems with ghost state
1413        "16421",
1414        "21653",
1415        "22660",
1416        "5225",
1417        "9846",
1418        "2426",
1419        "5916",
1420        "6634",
1421        //"6718", phasing stealth, annoying for learn all case.
1422        "6719",
1423        "8822",
1424        "9591",
1425        "9590",
1426        "10032",
1427        "17746",
1428        "17747",
1429        "8203",
1430        "11392",
1431        "12495",
1432        "16380",
1433        "23452",
1434        "4079",
1435        "4996",
1436        "4997",
1437        "4998",
1438        "4999",
1439        "5000",
1440        "6348",
1441        "6349",
1442        "6481",
1443        "6482",
1444        "6483",
1445        "6484",
1446        "11362",
1447        "11410",
1448        "11409",
1449        "12510",
1450        "12509",
1451        "12885",
1452        "13142",
1453        "21463",
1454        "23460",
1455        "11421",
1456        "11416",
1457        "11418",
1458        "1851",
1459        "10059",
1460        "11423",
1461        "11417",
1462        "11422",
1463        "11419",
1464        "11424",
1465        "11420",
1466        "27",
1467        "31",
1468        "33",
1469        "34",
1470        "35",
1471        "15125",
1472        "21127",
1473        "22950",
1474        "1180",
1475        "201",
1476        "12593",
1477        "12842",
1478        "16770",
1479        "6057",
1480        "12051",
1481        "18468",
1482        "12606",
1483        "12605",
1484        "18466",
1485        "12502",
1486        "12043",
1487        "15060",
1488        "12042",
1489        "12341",
1490        "12848",
1491        "12344",
1492        "12353",
1493        "18460",
1494        "11366",
1495        "12350",
1496        "12352",
1497        "13043",
1498        "11368",
1499        "11113",
1500        "12400",
1501        "11129",
1502        "16766",
1503        "12573",
1504        "15053",
1505        "12580",
1506        "12475",
1507        "12472",
1508        "12953",
1509        "12488",
1510        "11189",
1511        "12985",
1512        "12519",
1513        "16758",
1514        "11958",
1515        "12490",
1516        "11426",
1517        "3565",
1518        "3562",
1519        "18960",
1520        "3567",
1521        "3561",
1522        "3566",
1523        "3563",
1524        "1953",
1525        "2139",
1526        "12505",
1527        "13018",
1528        "12522",
1529        "12523",
1530        "5146",
1531        "5144",
1532        "5148",
1533        "8419",
1534        "8418",
1535        "10213",
1536        "10212",
1537        "10157",
1538        "12524",
1539        "13019",
1540        "12525",
1541        "13020",
1542        "12526",
1543        "13021",
1544        "18809",
1545        "13031",
1546        "13032",
1547        "13033",
1548        "4036",
1549        "3920",
1550        "3919",
1551        "3918",
1552        "7430",
1553        "3922",
1554        "3923",
1555        "7411",
1556        "7418",
1557        "7421",
1558        "13262",
1559        "7412",
1560        "7415",
1561        "7413",
1562        "7416",
1563        "13920",
1564        "13921",
1565        "7745",
1566        "7779",
1567        "7428",
1568        "7457",
1569        "7857",
1570        "7748",
1571        "7426",
1572        "13421",
1573        "7454",
1574        "13378",
1575        "7788",
1576        "14807",
1577        "14293",
1578        "7795",
1579        "6296",
1580        "20608",
1581        "755",
1582        "444",
1583        "427",
1584        "428",
1585        "442",
1586        "447",
1587        "3578",
1588        "3581",
1589        "19027",
1590        "3580",
1591        "665",
1592        "3579",
1593        "3577",
1594        "6755",
1595        "3576",
1596        "2575",
1597        "2577",
1598        "2578",
1599        "2579",
1600        "2580",
1601        "2656",
1602        "2657",
1603        "2576",
1604        "3564",
1605        "10248",
1606        "8388",
1607        "2659",
1608        "14891",
1609        "3308",
1610        "3307",
1611        "10097",
1612        "2658",
1613        "3569",
1614        "16153",
1615        "3304",
1616        "10098",
1617        "4037",
1618        "3929",
1619        "3931",
1620        "3926",
1621        "3924",
1622        "3930",
1623        "3977",
1624        "3925",
1625        "136",
1626        "228",
1627        "5487",
1628        "43",
1629        "202",
1630        "0"
1631    };
1632
1633    int loop = 0;
1634    while(strcmp(allSpellList[loop], "0"))
1635    {
1636        uint32 spell = atol((char*)allSpellList[loop++]);
1637
1638        if (m_session->GetPlayer()->HasSpell(spell))
1639            continue;
1640
1641        SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1642        if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1643        {
1644            PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1645            continue;
1646        }
1647
1648        m_session->GetPlayer()->learnSpell(spell);
1649    }
1650
1651    SendSysMessage(LANG_COMMAND_LEARN_MANY_SPELLS);
1652
1653    return true;
1654}
1655
1656bool ChatHandler::HandleLearnAllGMCommand(const char* /*args*/)
1657{
1658    static const char *gmSpellList[] =
1659    {
1660        "24347",                                            // Become A Fish, No Breath Bar
1661        "35132",                                            // Visual Boom
1662        "38488",                                            // Attack 4000-8000 AOE
1663        "38795",                                            // Attack 2000 AOE + Slow Down 90%
1664        "15712",                                            // Attack 200
1665        "1852",                                             // GM Spell Silence
1666        "31899",                                            // Kill
1667        "31924",                                            // Kill
1668        "29878",                                            // Kill My Self
1669        "26644",                                            // More Kill
1670
1671        "28550",                                            //Invisible 24
1672        "23452",                                            //Invisible + Target
1673        "0"
1674    };
1675
1676    uint16 gmSpellIter = 0;
1677    while( strcmp(gmSpellList[gmSpellIter], "0") )
1678    {
1679        uint32 spell = atol((char*)gmSpellList[gmSpellIter++]);
1680
1681        SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1682        if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1683        {
1684            PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1685            continue;
1686        }
1687
1688        m_session->GetPlayer()->learnSpell(spell);
1689    }
1690
1691    SendSysMessage(LANG_LEARNING_GM_SKILLS);
1692    return true;
1693}
1694
1695bool ChatHandler::HandleLearnAllMyClassCommand(const char* /*args*/)
1696{
1697    HandleLearnAllMySpellsCommand("");
1698    HandleLearnAllMyTalentsCommand("");
1699    return true;
1700}
1701
1702bool ChatHandler::HandleLearnAllMySpellsCommand(const char* /*args*/)
1703{
1704    ChrClassesEntry const* clsEntry = sChrClassesStore.LookupEntry(m_session->GetPlayer()->getClass());
1705    if(!clsEntry)
1706        return true;
1707    uint32 family = clsEntry->spellfamily;
1708
1709    for (uint32 i = 0; i < sSpellStore.GetNumRows(); i++)
1710    {
1711        SpellEntry const *spellInfo = sSpellStore.LookupEntry(i);
1712        if(!spellInfo)
1713            continue;
1714
1715        // skip wrong class/race skills
1716        if(!m_session->GetPlayer()->IsSpellFitByClassAndRace(spellInfo->Id))
1717            continue;
1718
1719        // skip other spell families
1720        if( spellInfo->SpellFamilyName != family)
1721            continue;
1722
1723        //TODO: skip triggered spells
1724
1725        // skip spells with first rank learned as talent (and all talents then also)
1726        uint32 first_rank = spellmgr.GetFirstSpellInChain(spellInfo->Id);
1727        if(GetTalentSpellCost(first_rank) > 0 )
1728            continue;
1729
1730        // skip broken spells
1731        if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1732            continue;
1733
1734        m_session->GetPlayer()->learnSpell(i);
1735    }
1736
1737    SendSysMessage(LANG_COMMAND_LEARN_CLASS_SPELLS);
1738    return true;
1739}
1740
1741static void learnAllHighRanks(Player* player, uint32 spellid)
1742{
1743    SpellChainMapNext const& nextMap = spellmgr.GetSpellChainNext();
1744    for(SpellChainMapNext::const_iterator itr = nextMap.lower_bound(spellid); itr != nextMap.upper_bound(spellid); ++itr)
1745    {
1746        player->learnSpell(itr->second);
1747        learnAllHighRanks(player,itr->second);
1748    }
1749}
1750
1751bool ChatHandler::HandleLearnAllMyTalentsCommand(const char* /*args*/)
1752{
1753    Player* player = m_session->GetPlayer();
1754    uint32 classMask = player->getClassMask();
1755
1756    for (uint32 i = 0; i < sTalentStore.GetNumRows(); i++)
1757    {
1758        TalentEntry const *talentInfo = sTalentStore.LookupEntry(i);
1759        if(!talentInfo)
1760            continue;
1761
1762        TalentTabEntry const *talentTabInfo = sTalentTabStore.LookupEntry( talentInfo->TalentTab );
1763        if(!talentTabInfo)
1764            continue;
1765
1766        if( (classMask & talentTabInfo->ClassMask) == 0 )
1767            continue;
1768
1769        // search highest talent rank
1770        uint32 spellid = 0;
1771        int rank = 4;
1772        for(; rank >= 0; --rank)
1773        {
1774            if(talentInfo->RankID[rank]!=0)
1775            {
1776                spellid = talentInfo->RankID[rank];
1777                break;
1778            }
1779        }
1780
1781        if(!spellid)                                        // ??? none spells in talent
1782            continue;
1783
1784        SpellEntry const* spellInfo = sSpellStore.LookupEntry(spellid);
1785        if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer(),false))
1786            continue;
1787
1788        // learn highest rank of talent
1789        player->learnSpell(spellid);
1790
1791        // and learn all non-talent spell ranks (recursive by tree)
1792        learnAllHighRanks(player,spellid);
1793    }
1794
1795    SendSysMessage(LANG_COMMAND_LEARN_CLASS_TALENTS);
1796    return true;
1797}
1798
1799bool ChatHandler::HandleLearnAllLangCommand(const char* /*args*/)
1800{
1801    // skipping UNIVERSAL language (0)
1802    for(int i = 1; i < LANGUAGES_COUNT; ++i)
1803        m_session->GetPlayer()->learnSpell(lang_description[i].spell_id);
1804
1805    SendSysMessage(LANG_COMMAND_LEARN_ALL_LANG);
1806    return true;
1807}
1808
1809bool ChatHandler::HandleLearnAllDefaultCommand(const char* args)
1810{
1811    char* pName = strtok((char*)args, "");
1812    Player *player = NULL;
1813    if (pName)
1814    {
1815        std::string name = pName;
1816
1817        if(!normalizePlayerName(name))
1818        {
1819            SendSysMessage(LANG_PLAYER_NOT_FOUND);
1820            SetSentErrorMessage(true);
1821            return false;
1822        }
1823
1824        player = objmgr.GetPlayer(name.c_str());
1825    }
1826    else
1827        player = getSelectedPlayer();
1828
1829    if(!player)
1830    {
1831        SendSysMessage(LANG_NO_CHAR_SELECTED);
1832        SetSentErrorMessage(true);
1833        return false;
1834    }
1835
1836    player->learnDefaultSpells();
1837    player->learnQuestRewardedSpells();
1838
1839    PSendSysMessage(LANG_COMMAND_LEARN_ALL_DEFAULT_AND_QUEST,player->GetName());
1840    return true;
1841}
1842
1843bool ChatHandler::HandleLearnCommand(const char* args)
1844{
1845    Player* targetPlayer = getSelectedPlayer();
1846
1847    if(!targetPlayer)
1848    {
1849        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1850        SetSentErrorMessage(true);
1851        return false;
1852    }
1853
1854    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
1855    uint32 spell = extractSpellIdFromLink((char*)args);
1856    if(!spell || !sSpellStore.LookupEntry(spell))
1857        return false;
1858
1859    if (targetPlayer->HasSpell(spell))
1860    {
1861        if(targetPlayer == m_session->GetPlayer())
1862            SendSysMessage(LANG_YOU_KNOWN_SPELL);
1863        else
1864            PSendSysMessage(LANG_TARGET_KNOWN_SPELL,targetPlayer->GetName());
1865        SetSentErrorMessage(true);
1866        return false;
1867    }
1868
1869    SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
1870    if(!spellInfo || !SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
1871    {
1872        PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
1873        SetSentErrorMessage(true);
1874        return false;
1875    }
1876
1877    targetPlayer->learnSpell(spell);
1878
1879    return true;
1880}
1881
1882bool ChatHandler::HandleAddItemCommand(const char* args)
1883{
1884    if (!*args)
1885        return false;
1886
1887    uint32 itemId = 0;
1888
1889    if(args[0]=='[')                                        // [name] manual form
1890    {
1891        char* citemName = citemName = strtok((char*)args, "]");
1892
1893        if(citemName && citemName[0])
1894        {
1895            std::string itemName = citemName+1;
1896            WorldDatabase.escape_string(itemName);
1897            QueryResult *result = WorldDatabase.PQuery("SELECT entry FROM item_template WHERE name = '%s'", itemName.c_str());
1898            if (!result)
1899            {
1900                PSendSysMessage(LANG_COMMAND_COULDNOTFIND, citemName+1);
1901                SetSentErrorMessage(true);
1902                return false;
1903            }
1904            itemId = result->Fetch()->GetUInt16();
1905            delete result;
1906        }
1907        else
1908            return false;
1909    }
1910    else                                                    // item_id or [name] Shift-click form |color|Hitem:item_id:0:0:0|h[name]|h|r
1911    {
1912        char* cId = extractKeyFromLink((char*)args,"Hitem");
1913        if(!cId)
1914            return false;
1915        itemId = atol(cId);
1916    }
1917
1918    char* ccount = strtok(NULL, " ");
1919
1920    int32 count = 1;
1921
1922    if (ccount)
1923        count = strtol(ccount, NULL, 10);
1924
1925    if (count == 0)
1926        count = 1;
1927
1928    Player* pl = m_session->GetPlayer();
1929    Player* plTarget = getSelectedPlayer();
1930    if(!plTarget)
1931        plTarget = pl;
1932
1933    sLog.outDetail(GetTrinityString(LANG_ADDITEM), itemId, count);
1934
1935    ItemPrototype const *pProto = objmgr.GetItemPrototype(itemId);
1936    if(!pProto)
1937    {
1938        PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, itemId);
1939        SetSentErrorMessage(true);
1940        return false;
1941    }
1942
1943    //Subtract
1944    if (count < 0)
1945    {
1946        plTarget->DestroyItemCount(itemId, -count, true, false);
1947        PSendSysMessage(LANG_REMOVEITEM, itemId, -count, plTarget->GetName());
1948        return true;
1949    }
1950
1951    //Adding items
1952    uint32 noSpaceForCount = 0;
1953
1954    // check space and find places
1955    ItemPosCountVec dest;
1956    uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, itemId, count, &noSpaceForCount );
1957    if( msg != EQUIP_ERR_OK )                               // convert to possible store amount
1958        count -= noSpaceForCount;
1959
1960    if( count == 0 || dest.empty())                         // can't add any
1961    {
1962        PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount );
1963        SetSentErrorMessage(true);
1964        return false;
1965    }
1966
1967    Item* item = plTarget->StoreNewItem( dest, itemId, true, Item::GenerateItemRandomPropertyId(itemId));
1968
1969    // remove binding (let GM give it to another player later)
1970    if(pl==plTarget)
1971        for(ItemPosCountVec::const_iterator itr = dest.begin(); itr != dest.end(); ++itr)
1972            if(Item* item1 = pl->GetItemByPos(itr->pos))
1973                item1->SetBinding( false );
1974
1975    if(count > 0 && item)
1976    {
1977        pl->SendNewItem(item,count,false,true);
1978        if(pl!=plTarget)
1979            plTarget->SendNewItem(item,count,true,false);
1980    }
1981
1982    if(noSpaceForCount > 0)
1983        PSendSysMessage(LANG_ITEM_CANNOT_CREATE, itemId, noSpaceForCount);
1984
1985    return true;
1986}
1987
1988bool ChatHandler::HandleAddItemSetCommand(const char* args)
1989{
1990    if (!*args)
1991        return false;
1992
1993    char* cId = extractKeyFromLink((char*)args,"Hitemset"); // number or [name] Shift-click form |color|Hitemset:itemset_id|h[name]|h|r
1994    if (!cId)
1995        return false;
1996
1997    uint32 itemsetId = atol(cId);
1998
1999    // prevent generation all items with itemset field value '0'
2000    if (itemsetId == 0)
2001    {
2002        PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2003        SetSentErrorMessage(true);
2004        return false;
2005    }
2006
2007    Player* pl = m_session->GetPlayer();
2008    Player* plTarget = getSelectedPlayer();
2009    if(!plTarget)
2010        plTarget = pl;
2011
2012    sLog.outDetail(GetTrinityString(LANG_ADDITEMSET), itemsetId);
2013
2014    bool found = false;
2015    for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2016    {
2017        ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
2018        if (!pProto)
2019            continue;
2020
2021        if (pProto->ItemSet == itemsetId)
2022        {
2023            found = true;
2024            ItemPosCountVec dest;
2025            uint8 msg = plTarget->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, pProto->ItemId, 1 );
2026            if (msg == EQUIP_ERR_OK)
2027            {
2028                Item* item = plTarget->StoreNewItem( dest, pProto->ItemId, true);
2029
2030                // remove binding (let GM give it to another player later)
2031                if (pl==plTarget)
2032                    item->SetBinding( false );
2033
2034                pl->SendNewItem(item,1,false,true);
2035                if (pl!=plTarget)
2036                    plTarget->SendNewItem(item,1,true,false);
2037            }
2038            else
2039            {
2040                pl->SendEquipError( msg, NULL, NULL );
2041                PSendSysMessage(LANG_ITEM_CANNOT_CREATE, pProto->ItemId, 1);
2042            }
2043        }
2044    }
2045
2046    if (!found)
2047    {
2048        PSendSysMessage(LANG_NO_ITEMS_FROM_ITEMSET_FOUND,itemsetId);
2049
2050        SetSentErrorMessage(true);
2051        return false;
2052    }
2053
2054    return true;
2055}
2056
2057bool ChatHandler::HandleListItemCommand(const char* args)
2058{
2059    if(!*args)
2060        return false;
2061
2062    char* cId = extractKeyFromLink((char*)args,"Hitem");
2063    if(!cId)
2064        return false;
2065
2066    uint32 item_id = atol(cId);
2067    if(!item_id)
2068    {
2069        PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2070        SetSentErrorMessage(true);
2071        return false;
2072    }
2073
2074    ItemPrototype const* itemProto = objmgr.GetItemPrototype(item_id);
2075    if(!itemProto)
2076    {
2077        PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
2078        SetSentErrorMessage(true);
2079        return false;
2080    }
2081
2082    char* c_count = strtok(NULL, " ");
2083    int count = c_count ? atol(c_count) : 10;
2084
2085    if(count < 0)
2086        return false;
2087
2088    QueryResult *result;
2089
2090    // inventory case
2091    uint32 inv_count = 0;
2092    result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM character_inventory WHERE item_template='%u'",item_id);
2093    if(result)
2094    {
2095        inv_count = (*result)[0].GetUInt32();
2096        delete result;
2097    }
2098
2099    result=CharacterDatabase.PQuery(
2100    //          0        1             2             3        4                  5
2101        "SELECT ci.item, cibag.slot AS bag, ci.slot, ci.guid, characters.account,characters.name "
2102        "FROM character_inventory AS ci LEFT JOIN character_inventory AS cibag ON (cibag.item=ci.bag),characters "
2103        "WHERE ci.item_template='%u' AND ci.guid = characters.guid LIMIT %u ",
2104        item_id,uint32(count));
2105
2106    if(result)
2107    {
2108        do
2109        {
2110            Field *fields = result->Fetch();
2111            uint32 item_guid = fields[0].GetUInt32();
2112            uint32 item_bag = fields[1].GetUInt32();
2113            uint32 item_slot = fields[2].GetUInt32();
2114            uint32 owner_guid = fields[3].GetUInt32();
2115            uint32 owner_acc = fields[4].GetUInt32();
2116            std::string owner_name = fields[5].GetCppString();
2117
2118            char const* item_pos = 0;
2119            if(Player::IsEquipmentPos(item_bag,item_slot))
2120                item_pos = "[equipped]";
2121            else if(Player::IsInventoryPos(item_bag,item_slot))
2122                item_pos = "[in inventory]";
2123            else if(Player::IsBankPos(item_bag,item_slot))
2124                item_pos = "[in bank]";
2125            else
2126                item_pos = "";
2127
2128            PSendSysMessage(LANG_ITEMLIST_SLOT,
2129                item_guid,owner_name.c_str(),owner_guid,owner_acc,item_pos);
2130        } while (result->NextRow());
2131
2132        int64 res_count = result->GetRowCount();
2133
2134        delete result;
2135
2136        if(count > res_count)
2137            count-=res_count;
2138        else if(count)
2139            count = 0;
2140    }
2141
2142    // mail case
2143    uint32 mail_count = 0;
2144    result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM mail_items WHERE item_template='%u'", item_id);
2145    if(result)
2146    {
2147        mail_count = (*result)[0].GetUInt32();
2148        delete result;
2149    }
2150
2151    if(count > 0)
2152    {
2153        result=CharacterDatabase.PQuery(
2154        //          0                     1            2              3               4            5               6
2155            "SELECT mail_items.item_guid, mail.sender, mail.receiver, char_s.account, char_s.name, char_r.account, char_r.name "
2156            "FROM mail,mail_items,characters as char_s,characters as char_r "
2157            "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",
2158            item_id,uint32(count));
2159    }
2160    else
2161        result = NULL;
2162
2163    if(result)
2164    {
2165        do
2166        {
2167            Field *fields = result->Fetch();
2168            uint32 item_guid        = fields[0].GetUInt32();
2169            uint32 item_s           = fields[1].GetUInt32();
2170            uint32 item_r           = fields[2].GetUInt32();
2171            uint32 item_s_acc       = fields[3].GetUInt32();
2172            std::string item_s_name = fields[4].GetCppString();
2173            uint32 item_r_acc       = fields[5].GetUInt32();
2174            std::string item_r_name = fields[6].GetCppString();
2175
2176            char const* item_pos = "[in mail]";
2177
2178            PSendSysMessage(LANG_ITEMLIST_MAIL,
2179                item_guid,item_s_name.c_str(),item_s,item_s_acc,item_r_name.c_str(),item_r,item_r_acc,item_pos);
2180        } while (result->NextRow());
2181
2182        int64 res_count = result->GetRowCount();
2183
2184        delete result;
2185
2186        if(count > res_count)
2187            count-=res_count;
2188        else if(count)
2189            count = 0;
2190    }
2191
2192    // auction case
2193    uint32 auc_count = 0;
2194    result=CharacterDatabase.PQuery("SELECT COUNT(item_template) FROM auctionhouse WHERE item_template='%u'",item_id);
2195    if(result)
2196    {
2197        auc_count = (*result)[0].GetUInt32();
2198        delete result;
2199    }
2200
2201    if(count > 0)
2202    {
2203        result=CharacterDatabase.PQuery(
2204        //           0                      1                       2                   3
2205            "SELECT  auctionhouse.itemguid, auctionhouse.itemowner, characters.account, characters.name "
2206            "FROM auctionhouse,characters WHERE auctionhouse.item_template='%u' AND characters.guid = auctionhouse.itemowner LIMIT %u",
2207            item_id,uint32(count));
2208    }
2209    else
2210        result = NULL;
2211
2212    if(result)
2213    {
2214        do
2215        {
2216            Field *fields = result->Fetch();
2217            uint32 item_guid       = fields[0].GetUInt32();
2218            uint32 owner           = fields[1].GetUInt32();
2219            uint32 owner_acc       = fields[2].GetUInt32();
2220            std::string owner_name = fields[3].GetCppString();
2221
2222            char const* item_pos = "[in auction]";
2223
2224            PSendSysMessage(LANG_ITEMLIST_AUCTION, item_guid, owner_name.c_str(), owner, owner_acc,item_pos);
2225        } while (result->NextRow());
2226
2227        delete result;
2228    }
2229
2230    // guild bank case
2231    uint32 guild_count = 0;
2232    result=CharacterDatabase.PQuery("SELECT COUNT(item_entry) FROM guild_bank_item WHERE item_entry='%u'",item_id);
2233    if(result)
2234    {
2235        guild_count = (*result)[0].GetUInt32();
2236        delete result;
2237    }
2238
2239    result=CharacterDatabase.PQuery(
2240        //      0             1           2
2241        "SELECT gi.item_guid, gi.guildid, guild.name "
2242        "FROM guild_bank_item AS gi, guild WHERE gi.item_entry='%u' AND gi.guildid = guild.guildid LIMIT %u ",
2243        item_id,uint32(count));
2244
2245    if(result)
2246    {
2247        do
2248        {
2249            Field *fields = result->Fetch();
2250            uint32 item_guid = fields[0].GetUInt32();
2251            uint32 guild_guid = fields[1].GetUInt32();
2252            std::string guild_name = fields[2].GetCppString();
2253
2254            char const* item_pos = "[in guild bank]";
2255
2256            PSendSysMessage(LANG_ITEMLIST_GUILD,item_guid,guild_name.c_str(),guild_guid,item_pos);
2257        } while (result->NextRow());
2258
2259        int64 res_count = result->GetRowCount();
2260
2261        delete result;
2262
2263        if(count > res_count)
2264            count-=res_count;
2265        else if(count)
2266            count = 0;
2267    }
2268
2269    if(inv_count+mail_count+auc_count+guild_count == 0)
2270    {
2271        SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2272        SetSentErrorMessage(true);
2273        return false;
2274    }
2275
2276    PSendSysMessage(LANG_COMMAND_LISTITEMMESSAGE,item_id,inv_count+mail_count+auc_count+guild_count,inv_count,mail_count,auc_count,guild_count);
2277
2278    return true;
2279}
2280
2281bool ChatHandler::HandleListObjectCommand(const char* args)
2282{
2283    if(!*args)
2284        return false;
2285
2286    // number or [name] Shift-click form |color|Hgameobject_entry:go_id|h[name]|h|r
2287    char* cId = extractKeyFromLink((char*)args,"Hgameobject_entry");
2288    if(!cId)
2289        return false;
2290
2291    uint32 go_id = atol(cId);
2292    if(!go_id)
2293    {
2294        PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2295        SetSentErrorMessage(true);
2296        return false;
2297    }
2298
2299    GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(go_id);
2300    if(!gInfo)
2301    {
2302        PSendSysMessage(LANG_COMMAND_LISTOBJINVALIDID, go_id);
2303        SetSentErrorMessage(true);
2304        return false;
2305    }
2306
2307    char* c_count = strtok(NULL, " ");
2308    int count = c_count ? atol(c_count) : 10;
2309
2310    if(count < 0)
2311        return false;
2312
2313    QueryResult *result;
2314
2315    uint32 obj_count = 0;
2316    result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM gameobject WHERE id='%u'",go_id);
2317    if(result)
2318    {
2319        obj_count = (*result)[0].GetUInt32();
2320        delete result;
2321    }
2322
2323    if(m_session)
2324    {
2325        Player* pl = m_session->GetPlayer();
2326        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",
2327            pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),go_id,uint32(count));
2328    }
2329    else
2330        result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM gameobject WHERE id = '%u' LIMIT %u",
2331            go_id,uint32(count));
2332
2333    if (result)
2334    {
2335        do
2336        {
2337            Field *fields = result->Fetch();
2338            uint32 guid = fields[0].GetUInt32();
2339            float x = fields[1].GetFloat();
2340            float y = fields[2].GetFloat();
2341            float z = fields[3].GetFloat();
2342            int mapid = fields[4].GetUInt16();
2343
2344            if (m_session)
2345                PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2346            else
2347                PSendSysMessage(LANG_GO_LIST_CONSOLE, guid, gInfo->name, x, y, z, mapid);
2348        } while (result->NextRow());
2349
2350        delete result;
2351    }
2352
2353    PSendSysMessage(LANG_COMMAND_LISTOBJMESSAGE,go_id,obj_count);
2354    return true;
2355}
2356
2357bool ChatHandler::HandleNearObjectCommand(const char* args)
2358{
2359    float distance = (!*args) ? 10 : atol(args);
2360    uint32 count = 0;
2361
2362    Player* pl = m_session->GetPlayer();
2363    QueryResult *result = WorldDatabase.PQuery("SELECT guid, id, position_x, position_y, position_z, map, "
2364        "(POW(position_x - '%f', 2) + POW(position_y - '%f', 2) + POW(position_z - '%f', 2)) AS order_ "
2365        "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_",
2366        pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),
2367        pl->GetMapId(),pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(),distance*distance);
2368
2369    if (result)
2370    {
2371        do
2372        {
2373            Field *fields = result->Fetch();
2374            uint32 guid = fields[0].GetUInt32();
2375            uint32 entry = fields[1].GetUInt32();
2376            float x = fields[2].GetFloat();
2377            float y = fields[3].GetFloat();
2378            float z = fields[4].GetFloat();
2379            int mapid = fields[5].GetUInt16();
2380
2381            GameObjectInfo const * gInfo = objmgr.GetGameObjectInfo(entry);
2382
2383            if(!gInfo)
2384                continue;
2385
2386            PSendSysMessage(LANG_GO_LIST_CHAT, guid, guid, gInfo->name, x, y, z, mapid);
2387
2388            ++count;
2389        } while (result->NextRow());
2390
2391        delete result;
2392    }
2393
2394    PSendSysMessage(LANG_COMMAND_NEAROBJMESSAGE,distance,count);
2395    return true;
2396}
2397
2398bool ChatHandler::HandleObjectStateCommand(const char* args)
2399{
2400    // number or [name] Shift-click form |color|Hgameobject:go_id|h[name]|h|r
2401    char* cId = extractKeyFromLink((char*)args, "Hgameobject");
2402    if(!cId)
2403        return false;
2404
2405    uint32 lowguid = atoi(cId);
2406    if(!lowguid)
2407        return false;
2408
2409    GameObject* gobj = NULL;
2410
2411    if(GameObjectData const* goData = objmgr.GetGOData(lowguid))
2412        gobj = GetObjectGlobalyWithGuidOrNearWithDbGuid(lowguid, goData->id);
2413
2414    if(!gobj)
2415    {
2416        PSendSysMessage(LANG_COMMAND_OBJNOTFOUND, lowguid);
2417        SetSentErrorMessage(true);
2418        return false;
2419    }
2420
2421    char* cstate = strtok(NULL, " ");
2422    if(!cstate)
2423        return false;
2424
2425    int32 state = atoi(cstate);
2426    if(state < 0)
2427        gobj->SendObjectDeSpawnAnim(gobj->GetGUID());
2428    else
2429        gobj->SetGoState(state);
2430
2431    return true;
2432
2433    return true;
2434}
2435
2436bool ChatHandler::HandleListCreatureCommand(const char* args)
2437{
2438    if(!*args)
2439        return false;
2440
2441    // number or [name] Shift-click form |color|Hcreature_entry:creature_id|h[name]|h|r
2442    char* cId = extractKeyFromLink((char*)args,"Hcreature_entry");
2443    if(!cId)
2444        return false;
2445
2446    uint32 cr_id = atol(cId);
2447    if(!cr_id)
2448    {
2449        PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2450        SetSentErrorMessage(true);
2451        return false;
2452    }
2453
2454    CreatureInfo const* cInfo = objmgr.GetCreatureTemplate(cr_id);
2455    if(!cInfo)
2456    {
2457        PSendSysMessage(LANG_COMMAND_INVALIDCREATUREID, cr_id);
2458        SetSentErrorMessage(true);
2459        return false;
2460    }
2461
2462    char* c_count = strtok(NULL, " ");
2463    int count = c_count ? atol(c_count) : 10;
2464
2465    if(count < 0)
2466        return false;
2467
2468    QueryResult *result;
2469
2470    uint32 cr_count = 0;
2471    result=WorldDatabase.PQuery("SELECT COUNT(guid) FROM creature WHERE id='%u'",cr_id);
2472    if(result)
2473    {
2474        cr_count = (*result)[0].GetUInt32();
2475        delete result;
2476    }
2477
2478    if(m_session)
2479    {
2480        Player* pl = m_session->GetPlayer();
2481        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",
2482            pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ(), cr_id,uint32(count));
2483    }
2484    else
2485        result = WorldDatabase.PQuery("SELECT guid, position_x, position_y, position_z, map FROM creature WHERE id = '%u' LIMIT %u",
2486            cr_id,uint32(count));
2487
2488    if (result)
2489    {
2490        do
2491        {
2492            Field *fields = result->Fetch();
2493            uint32 guid = fields[0].GetUInt32();
2494            float x = fields[1].GetFloat();
2495            float y = fields[2].GetFloat();
2496            float z = fields[3].GetFloat();
2497            int mapid = fields[4].GetUInt16();
2498
2499            if  (m_session)
2500                PSendSysMessage(LANG_CREATURE_LIST_CHAT, guid, guid, cInfo->Name, x, y, z, mapid);
2501            else
2502                PSendSysMessage(LANG_CREATURE_LIST_CONSOLE, guid, cInfo->Name, x, y, z, mapid);
2503        } while (result->NextRow());
2504
2505        delete result;
2506    }
2507
2508    PSendSysMessage(LANG_COMMAND_LISTCREATUREMESSAGE,cr_id,cr_count);
2509    return true;
2510}
2511
2512bool ChatHandler::HandleLookupItemCommand(const char* args)
2513{
2514    if(!*args)
2515        return false;
2516
2517    std::string namepart = args;
2518    std::wstring wnamepart;
2519
2520    // converting string that we try to find to lower case
2521    if(!Utf8toWStr(namepart,wnamepart))
2522        return false;
2523
2524    wstrToLower(wnamepart);
2525
2526    uint32 counter = 0;
2527
2528    // Search in `item_template`
2529    for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
2530    {
2531        ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype >(id);
2532        if(!pProto)
2533            continue;
2534
2535        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2536        if ( loc_idx >= 0 )
2537        {
2538            ItemLocale const *il = objmgr.GetItemLocale(pProto->ItemId);
2539            if (il)
2540            {
2541                if (il->Name.size() > loc_idx && !il->Name[loc_idx].empty())
2542                {
2543                    std::string name = il->Name[loc_idx];
2544
2545                    if (Utf8FitTo(name, wnamepart))
2546                    {
2547                        if (m_session)
2548                            PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2549                        else
2550                            PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2551                        ++counter;
2552                        continue;
2553                    }
2554                }
2555            }
2556        }
2557
2558        std::string name = pProto->Name1;
2559        if(name.empty())
2560            continue;
2561
2562        if (Utf8FitTo(name, wnamepart))
2563        {
2564            if (m_session)
2565                PSendSysMessage(LANG_ITEM_LIST_CHAT, id, id, name.c_str());
2566            else
2567                PSendSysMessage(LANG_ITEM_LIST_CONSOLE, id, name.c_str());
2568            ++counter;
2569        }
2570    }
2571
2572    if (counter==0)
2573        SendSysMessage(LANG_COMMAND_NOITEMFOUND);
2574
2575    return true;
2576}
2577
2578bool ChatHandler::HandleLookupItemSetCommand(const char* args)
2579{
2580    if(!*args)
2581        return false;
2582
2583    std::string namepart = args;
2584    std::wstring wnamepart;
2585
2586    if(!Utf8toWStr(namepart,wnamepart))
2587        return false;
2588
2589    // converting string that we try to find to lower case
2590    wstrToLower( wnamepart );
2591
2592    uint32 counter = 0;                                     // Counter for figure out that we found smth.
2593
2594    // Search in ItemSet.dbc
2595    for (uint32 id = 0; id < sItemSetStore.GetNumRows(); id++)
2596    {
2597        ItemSetEntry const *set = sItemSetStore.LookupEntry(id);
2598        if(set)
2599        {
2600            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2601            std::string name = set->name[loc];
2602            if(name.empty())
2603                continue;
2604
2605            if (!Utf8FitTo(name, wnamepart))
2606            {
2607                loc = 0;
2608                for(; loc < MAX_LOCALE; ++loc)
2609                {
2610                    if(m_session && loc==m_session->GetSessionDbcLocale())
2611                        continue;
2612
2613                    name = set->name[loc];
2614                    if(name.empty())
2615                        continue;
2616
2617                    if (Utf8FitTo(name, wnamepart))
2618                        break;
2619                }
2620            }
2621
2622            if(loc < MAX_LOCALE)
2623            {
2624                // send item set in "id - [namedlink locale]" format
2625                if (m_session)
2626                    PSendSysMessage(LANG_ITEMSET_LIST_CHAT,id,id,name.c_str(),localeNames[loc]);
2627                else
2628                    PSendSysMessage(LANG_ITEMSET_LIST_CONSOLE,id,name.c_str(),localeNames[loc]);
2629                ++counter;
2630            }
2631        }
2632    }
2633    if (counter == 0)                                       // if counter == 0 then we found nth
2634        SendSysMessage(LANG_COMMAND_NOITEMSETFOUND);
2635    return true;
2636}
2637
2638bool ChatHandler::HandleLookupSkillCommand(const char* args)
2639{
2640    if(!*args)
2641        return false;
2642
2643    // can be NULL in console call
2644    Player* target = getSelectedPlayer();
2645
2646    std::string namepart = args;
2647    std::wstring wnamepart;
2648
2649    if(!Utf8toWStr(namepart,wnamepart))
2650        return false;
2651
2652    // converting string that we try to find to lower case
2653    wstrToLower( wnamepart );
2654
2655    uint32 counter = 0;                                     // Counter for figure out that we found smth.
2656
2657    // Search in SkillLine.dbc
2658    for (uint32 id = 0; id < sSkillLineStore.GetNumRows(); id++)
2659    {
2660        SkillLineEntry const *skillInfo = sSkillLineStore.LookupEntry(id);
2661        if(skillInfo)
2662        {
2663            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2664            std::string name = skillInfo->name[loc];
2665            if(name.empty())
2666                continue;
2667
2668            if (!Utf8FitTo(name, wnamepart))
2669            {
2670                loc = 0;
2671                for(; loc < MAX_LOCALE; ++loc)
2672                {
2673                    if(m_session && loc==m_session->GetSessionDbcLocale())
2674                        continue;
2675
2676                    name = skillInfo->name[loc];
2677                    if(name.empty())
2678                        continue;
2679
2680                    if (Utf8FitTo(name, wnamepart))
2681                        break;
2682                }
2683            }
2684
2685            if(loc < MAX_LOCALE)
2686            {
2687                char const* knownStr = "";
2688                if(target && target->HasSkill(id))
2689                    knownStr = GetTrinityString(LANG_KNOWN);
2690
2691                // send skill in "id - [namedlink locale]" format
2692                if (m_session)
2693                    PSendSysMessage(LANG_SKILL_LIST_CHAT,id,id,name.c_str(),localeNames[loc],knownStr);
2694                else
2695                    PSendSysMessage(LANG_SKILL_LIST_CONSOLE,id,name.c_str(),localeNames[loc],knownStr);
2696
2697                ++counter;
2698            }
2699        }
2700    }
2701    if (counter == 0)                                       // if counter == 0 then we found nth
2702        SendSysMessage(LANG_COMMAND_NOSKILLFOUND);
2703    return true;
2704}
2705
2706bool ChatHandler::HandleLookupSpellCommand(const char* args)
2707{
2708    if(!*args)
2709        return false;
2710
2711    // can be NULL at console call
2712    Player* target = getSelectedPlayer();
2713
2714    std::string namepart = args;
2715    std::wstring wnamepart;
2716
2717    if(!Utf8toWStr(namepart,wnamepart))
2718        return false;
2719
2720    // converting string that we try to find to lower case
2721    wstrToLower( wnamepart );
2722
2723    uint32 counter = 0;                                     // Counter for figure out that we found smth.
2724
2725    // Search in Spell.dbc
2726    for (uint32 id = 0; id < sSpellStore.GetNumRows(); id++)
2727    {
2728        SpellEntry const *spellInfo = sSpellStore.LookupEntry(id);
2729        if(spellInfo)
2730        {
2731            int loc = m_session ? m_session->GetSessionDbcLocale() : sWorld.GetDefaultDbcLocale();
2732            std::string name = spellInfo->SpellName[loc];
2733            if(name.empty())
2734                continue;
2735
2736            if (!Utf8FitTo(name, wnamepart))
2737            {
2738                loc = 0;
2739                for(; loc < MAX_LOCALE; ++loc)
2740                {
2741                    if(m_session && loc==m_session->GetSessionDbcLocale())
2742                        continue;
2743
2744                    name = spellInfo->SpellName[loc];
2745                    if(name.empty())
2746                        continue;
2747
2748                    if (Utf8FitTo(name, wnamepart))
2749                        break;
2750                }
2751            }
2752
2753            if(loc < MAX_LOCALE)
2754            {
2755                bool known = target && target->HasSpell(id);
2756                bool learn = (spellInfo->Effect[0] == SPELL_EFFECT_LEARN_SPELL);
2757
2758                uint32 talentCost = GetTalentSpellCost(id);
2759
2760                bool talent = (talentCost > 0);
2761                bool passive = IsPassiveSpell(id);
2762                bool active = target && (target->HasAura(id,0) || target->HasAura(id,1) || target->HasAura(id,2));
2763
2764                // unit32 used to prevent interpreting uint8 as char at output
2765                // find rank of learned spell for learning spell, or talent rank
2766                uint32 rank = talentCost ? talentCost : spellmgr.GetSpellRank(learn ? spellInfo->EffectTriggerSpell[0] : id);
2767
2768                // send spell in "id - [name, rank N] [talent] [passive] [learn] [known]" format
2769                std::ostringstream ss;
2770                if (m_session)
2771                    ss << id << " - |cffffffff|Hspell:" << id << "|h[" << name;
2772                else
2773                    ss << id << " - " << name;
2774
2775                // include rank in link name
2776                if(rank)
2777                    ss << GetTrinityString(LANG_SPELL_RANK) << rank;
2778
2779                if (m_session)
2780                    ss << " " << localeNames[loc] << "]|h|r";
2781                else
2782                    ss << " " << localeNames[loc];
2783
2784                if(talent)
2785                    ss << GetTrinityString(LANG_TALENT);
2786                if(passive)
2787                    ss << GetTrinityString(LANG_PASSIVE);
2788                if(learn)
2789                    ss << GetTrinityString(LANG_LEARN);
2790                if(known)
2791                    ss << GetTrinityString(LANG_KNOWN);
2792                if(active)
2793                    ss << GetTrinityString(LANG_ACTIVE);
2794
2795                SendSysMessage(ss.str().c_str());
2796
2797                ++counter;
2798            }
2799        }
2800    }
2801    if (counter == 0)                                       // if counter == 0 then we found nth
2802        SendSysMessage(LANG_COMMAND_NOSPELLFOUND);
2803    return true;
2804}
2805
2806bool ChatHandler::HandleLookupQuestCommand(const char* args)
2807{
2808    if(!*args)
2809        return false;
2810
2811    // can be NULL at console call
2812    Player* target = getSelectedPlayer();
2813
2814    std::string namepart = args;
2815    std::wstring wnamepart;
2816
2817    // converting string that we try to find to lower case
2818    if(!Utf8toWStr(namepart,wnamepart))
2819        return false;
2820
2821    wstrToLower(wnamepart);
2822
2823    uint32 counter = 0 ;
2824
2825    ObjectMgr::QuestMap const& qTemplates = objmgr.GetQuestTemplates();
2826    for (ObjectMgr::QuestMap::const_iterator iter = qTemplates.begin(); iter != qTemplates.end(); ++iter)
2827    {
2828        Quest * qinfo = iter->second;
2829
2830        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2831        if ( loc_idx >= 0 )
2832        {
2833            QuestLocale const *il = objmgr.GetQuestLocale(qinfo->GetQuestId());
2834            if (il)
2835            {
2836                if (il->Title.size() > loc_idx && !il->Title[loc_idx].empty())
2837                {
2838                    std::string title = il->Title[loc_idx];
2839
2840                    if (Utf8FitTo(title, wnamepart))
2841                    {
2842                        char const* statusStr = "";
2843
2844                        if(target)
2845                        {
2846                            QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2847
2848                            if(status == QUEST_STATUS_COMPLETE)
2849                            {
2850                                if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2851                                    statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
2852                                else
2853                                    statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
2854                            }
2855                            else if(status == QUEST_STATUS_INCOMPLETE)
2856                                statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
2857                        }
2858
2859                        if (m_session)
2860                            PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2861                        else
2862                            PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2863                        ++counter;
2864                        continue;
2865                    }
2866                }
2867            }
2868        }
2869
2870        std::string title = qinfo->GetTitle();
2871        if(title.empty())
2872            continue;
2873
2874        if (Utf8FitTo(title, wnamepart))
2875        {
2876            char const* statusStr = "";
2877
2878            if(target)
2879            {
2880                QuestStatus status = target->GetQuestStatus(qinfo->GetQuestId());
2881
2882                if(status == QUEST_STATUS_COMPLETE)
2883                {
2884                    if(target->GetQuestRewardStatus(qinfo->GetQuestId()))
2885                        statusStr = GetTrinityString(LANG_COMMAND_QUEST_REWARDED);
2886                    else
2887                        statusStr = GetTrinityString(LANG_COMMAND_QUEST_COMPLETE);
2888                }
2889                else if(status == QUEST_STATUS_INCOMPLETE)
2890                    statusStr = GetTrinityString(LANG_COMMAND_QUEST_ACTIVE);
2891            }
2892
2893            if (m_session)
2894                PSendSysMessage(LANG_QUEST_LIST_CHAT,qinfo->GetQuestId(),qinfo->GetQuestId(),title.c_str(),statusStr);
2895            else
2896                PSendSysMessage(LANG_QUEST_LIST_CONSOLE,qinfo->GetQuestId(),title.c_str(),statusStr);
2897
2898            ++counter;
2899        }
2900    }
2901
2902    if (counter==0)
2903        SendSysMessage(LANG_COMMAND_NOQUESTFOUND);
2904
2905    return true;
2906}
2907
2908bool ChatHandler::HandleLookupCreatureCommand(const char* args)
2909{
2910    if (!*args)
2911        return false;
2912
2913    std::string namepart = args;
2914    std::wstring wnamepart;
2915
2916    // converting string that we try to find to lower case
2917    if (!Utf8toWStr (namepart,wnamepart))
2918        return false;
2919
2920    wstrToLower (wnamepart);
2921
2922    uint32 counter = 0;
2923
2924    for (uint32 id = 0; id< sCreatureStorage.MaxEntry; ++id)
2925    {
2926        CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo> (id);
2927        if(!cInfo)
2928            continue;
2929
2930        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2931        if (loc_idx >= 0)
2932        {
2933            CreatureLocale const *cl = objmgr.GetCreatureLocale (id);
2934            if (cl)
2935            {
2936                if (cl->Name.size() > loc_idx && !cl->Name[loc_idx].empty ())
2937                {
2938                    std::string name = cl->Name[loc_idx];
2939
2940                    if (Utf8FitTo (name, wnamepart))
2941                    {
2942                        if (m_session)
2943                            PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2944                        else
2945                            PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2946                        ++counter;
2947                        continue;
2948                    }
2949                }
2950            }
2951        }
2952
2953        std::string name = cInfo->Name;
2954        if (name.empty ())
2955            continue;
2956
2957        if (Utf8FitTo(name, wnamepart))
2958        {
2959            if (m_session)
2960                PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CHAT, id, id, name.c_str ());
2961            else
2962                PSendSysMessage (LANG_CREATURE_ENTRY_LIST_CONSOLE, id, name.c_str ());
2963            ++counter;
2964        }
2965    }
2966
2967    if (counter==0)
2968        SendSysMessage (LANG_COMMAND_NOCREATUREFOUND);
2969
2970    return true;
2971}
2972
2973bool ChatHandler::HandleLookupObjectCommand(const char* args)
2974{
2975    if(!*args)
2976        return false;
2977
2978    std::string namepart = args;
2979    std::wstring wnamepart;
2980
2981    // converting string that we try to find to lower case
2982    if(!Utf8toWStr(namepart,wnamepart))
2983        return false;
2984
2985    wstrToLower(wnamepart);
2986
2987    uint32 counter = 0;
2988
2989    for (uint32 id = 0; id< sGOStorage.MaxEntry; id++ )
2990    {
2991        GameObjectInfo const* gInfo = sGOStorage.LookupEntry<GameObjectInfo>(id);
2992        if(!gInfo)
2993            continue;
2994
2995        int loc_idx = m_session ? m_session->GetSessionDbLocaleIndex() : objmgr.GetDBCLocaleIndex();
2996        if ( loc_idx >= 0 )
2997        {
2998            GameObjectLocale const *gl = objmgr.GetGameObjectLocale(id);
2999            if (gl)
3000            {
3001                if (gl->Name.size() > loc_idx && !gl->Name[loc_idx].empty())
3002                {
3003                    std::string name = gl->Name[loc_idx];
3004
3005                    if (Utf8FitTo(name, wnamepart))
3006                    {
3007                        if (m_session)
3008                            PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3009                        else
3010                            PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3011                        ++counter;
3012                        continue;
3013                    }
3014                }
3015            }
3016        }
3017
3018        std::string name = gInfo->name;
3019        if(name.empty())
3020            continue;
3021
3022        if(Utf8FitTo(name, wnamepart))
3023        {
3024            if (m_session)
3025                PSendSysMessage(LANG_GO_ENTRY_LIST_CHAT, id, id, name.c_str());
3026            else
3027                PSendSysMessage(LANG_GO_ENTRY_LIST_CONSOLE, id, name.c_str());
3028            ++counter;
3029        }
3030    }
3031
3032    if(counter==0)
3033        SendSysMessage(LANG_COMMAND_NOGAMEOBJECTFOUND);
3034
3035    return true;
3036}
3037
3038/** \brief GM command level 3 - Create a guild.
3039 *
3040 * This command allows a GM (level 3) to create a guild.
3041 *
3042 * The "args" parameter contains the name of the guild leader
3043 * and then the name of the guild.
3044 *
3045 */
3046bool ChatHandler::HandleGuildCreateCommand(const char* args)
3047{
3048
3049    if (!*args)
3050        return false;
3051
3052    char *lname = strtok ((char*)args, " ");
3053    char *gname = strtok (NULL, "");
3054
3055    if (!lname)
3056        return false;
3057
3058    if (!gname)
3059    {
3060        SendSysMessage (LANG_INSERT_GUILD_NAME);
3061        SetSentErrorMessage (true);
3062        return false;
3063    }
3064
3065    std::string guildname = gname;
3066
3067    Player* player = ObjectAccessor::Instance ().FindPlayerByName (lname);
3068    if (!player)
3069    {
3070        SendSysMessage (LANG_PLAYER_NOT_FOUND);
3071        SetSentErrorMessage (true);
3072        return false;
3073    }
3074
3075    if (player->GetGuildId())
3076    {
3077        SendSysMessage (LANG_PLAYER_IN_GUILD);
3078        return true;
3079    }
3080
3081    Guild *guild = new Guild;
3082    if (!guild->create (player->GetGUID (),guildname))
3083    {
3084        delete guild;
3085        SendSysMessage (LANG_GUILD_NOT_CREATED);
3086        SetSentErrorMessage (true);
3087        return false;
3088    }
3089
3090    objmgr.AddGuild (guild);
3091    return true;
3092}
3093
3094bool ChatHandler::HandleGuildInviteCommand(const char *args)
3095{
3096    if (!*args)
3097        return false;
3098
3099    char* par1 = strtok ((char*)args, " ");
3100    char* par2 = strtok (NULL, "");
3101    if(!par1 || !par2)
3102        return false;
3103
3104    std::string glName = par2;
3105    Guild* targetGuild = objmgr.GetGuildByName (glName);
3106    if (!targetGuild)
3107        return false;
3108
3109    std::string plName = par1;
3110    if (!normalizePlayerName (plName))
3111    {
3112        SendSysMessage (LANG_PLAYER_NOT_FOUND);
3113        SetSentErrorMessage (true);
3114        return false;
3115    }
3116
3117    uint64 plGuid = 0;
3118    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3119        plGuid = targetPlayer->GetGUID ();
3120    else
3121        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3122
3123    if (!plGuid)
3124        false;
3125
3126    // player's guild membership checked in AddMember before add
3127    if (!targetGuild->AddMember (plGuid,targetGuild->GetLowestRank ()))
3128        return false;
3129
3130    return true;
3131}
3132
3133bool ChatHandler::HandleGuildUninviteCommand(const char *args)
3134{
3135    if (!*args)
3136        return false;
3137
3138    char* par1 = strtok ((char*)args, " ");
3139    if(!par1)
3140        return false;
3141
3142    std::string plName = par1;
3143    if (!normalizePlayerName (plName))
3144    {
3145        SendSysMessage (LANG_PLAYER_NOT_FOUND);
3146        SetSentErrorMessage (true);
3147        return false;
3148    }
3149
3150    uint64 plGuid = 0;
3151    uint32 glId   = 0;
3152    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3153    {
3154        plGuid = targetPlayer->GetGUID ();
3155        glId   = targetPlayer->GetGuildId ();
3156    }
3157    else
3158    {
3159        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3160        glId = Player::GetGuildIdFromDB (plGuid);
3161    }
3162
3163    if (!plGuid || !glId)
3164        return false;
3165
3166    Guild* targetGuild = objmgr.GetGuildById (glId);
3167    if (!targetGuild)
3168        return false;
3169
3170    targetGuild->DelMember (plGuid);
3171
3172    return true;
3173}
3174
3175bool ChatHandler::HandleGuildRankCommand(const char *args)
3176{
3177    if (!*args)
3178        return false;
3179
3180    char* par1 = strtok ((char*)args, " ");
3181    char* par2 = strtok (NULL, " ");
3182    if (!par1 || !par2)
3183        return false;
3184    std::string plName = par1;
3185    if (!normalizePlayerName (plName))
3186    {
3187        SendSysMessage (LANG_PLAYER_NOT_FOUND);
3188        SetSentErrorMessage (true);
3189        return false;
3190    }
3191
3192    uint64 plGuid = 0;
3193    uint32 glId   = 0;
3194    if (Player* targetPlayer = ObjectAccessor::Instance ().FindPlayerByName (plName.c_str ()))
3195    {
3196        plGuid = targetPlayer->GetGUID ();
3197        glId   = targetPlayer->GetGuildId ();
3198    }
3199    else
3200    {
3201        plGuid = objmgr.GetPlayerGUIDByName (plName.c_str ());
3202        glId = Player::GetGuildIdFromDB (plGuid);
3203    }
3204
3205    if (!plGuid || !glId)
3206        return false;
3207
3208    Guild* targetGuild = objmgr.GetGuildById (glId);
3209    if (!targetGuild)
3210        return false;
3211
3212    uint32 newrank = uint32 (atoi (par2));
3213    if (newrank > targetGuild->GetLowestRank ())
3214        return false;
3215
3216    targetGuild->ChangeRank (plGuid,newrank);
3217
3218    return true;
3219}
3220
3221bool ChatHandler::HandleGuildDeleteCommand(const char* args)
3222{
3223    if (!*args)
3224        return false;
3225
3226    char* par1 = strtok ((char*)args, " ");
3227    if (!par1)
3228        return false;
3229
3230    std::string gld = par1;
3231
3232    Guild* targetGuild = objmgr.GetGuildByName (gld);
3233    if (!targetGuild)
3234        return false;
3235
3236    targetGuild->Disband ();
3237
3238    return true;
3239}
3240
3241bool ChatHandler::HandleGetDistanceCommand(const char* /*args*/)
3242{
3243    Unit* pUnit = getSelectedUnit();
3244
3245    if(!pUnit)
3246    {
3247        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3248        SetSentErrorMessage(true);
3249        return false;
3250    }
3251
3252    PSendSysMessage(LANG_DISTANCE, m_session->GetPlayer()->GetDistance(pUnit),m_session->GetPlayer()->GetDistance2d(pUnit));
3253
3254    return true;
3255}
3256
3257// FIX-ME!!!
3258
3259bool ChatHandler::HandleAddWeaponCommand(const char* /*args*/)
3260{
3261    /*if (!*args)
3262        return false;
3263
3264    uint64 guid = m_session->GetPlayer()->GetSelection();
3265    if (guid == 0)
3266    {
3267        SendSysMessage(LANG_NO_SELECTION);
3268        return true;
3269    }
3270
3271    Creature *pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
3272
3273    if(!pCreature)
3274    {
3275        SendSysMessage(LANG_SELECT_CREATURE);
3276        return true;
3277    }
3278
3279    char* pSlotID = strtok((char*)args, " ");
3280    if (!pSlotID)
3281        return false;
3282
3283    char* pItemID = strtok(NULL, " ");
3284    if (!pItemID)
3285        return false;
3286
3287    uint32 ItemID = atoi(pItemID);
3288    uint32 SlotID = atoi(pSlotID);
3289
3290    ItemPrototype* tmpItem = objmgr.GetItemPrototype(ItemID);
3291
3292    bool added = false;
3293    if(tmpItem)
3294    {
3295        switch(SlotID)
3296        {
3297            case 1:
3298                pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY, ItemID);
3299                added = true;
3300                break;
3301            case 2:
3302                pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_01, ItemID);
3303                added = true;
3304                break;
3305            case 3:
3306                pCreature->SetUInt32Value(UNIT_VIRTUAL_ITEM_SLOT_DISPLAY_02, ItemID);
3307                added = true;
3308                break;
3309            default:
3310                PSendSysMessage(LANG_ITEM_SLOT_NOT_EXIST,SlotID);
3311                added = false;
3312                break;
3313        }
3314        if(added)
3315        {
3316            PSendSysMessage(LANG_ITEM_ADDED_TO_SLOT,ItemID,tmpItem->Name1,SlotID);
3317        }
3318    }
3319    else
3320    {
3321        PSendSysMessage(LANG_ITEM_NOT_FOUND,ItemID);
3322        return true;
3323    }
3324    */
3325    return true;
3326}
3327
3328bool ChatHandler::HandleDieCommand(const char* /*args*/)
3329{
3330    Unit* target = getSelectedUnit();
3331
3332    if(!target || !m_session->GetPlayer()->GetSelection())
3333    {
3334        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3335        SetSentErrorMessage(true);
3336        return false;
3337    }
3338
3339    if( target->isAlive() )
3340    {
3341        m_session->GetPlayer()->DealDamage(target, target->GetHealth(), NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3342    }
3343
3344    return true;
3345}
3346
3347bool ChatHandler::HandleDamageCommand(const char * args)
3348{
3349    if (!*args)
3350        return false;
3351
3352    Unit* target = getSelectedUnit();
3353
3354    if(!target || !m_session->GetPlayer()->GetSelection())
3355    {
3356        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3357        SetSentErrorMessage(true);
3358        return false;
3359    }
3360
3361    if( !target->isAlive() )
3362        return true;
3363
3364    char* damageStr = strtok((char*)args, " ");
3365    if(!damageStr)
3366        return false;
3367
3368    int32 damage = atoi((char*)damageStr);
3369    if(damage <=0)
3370        return true;
3371
3372    char* schoolStr = strtok((char*)NULL, " ");
3373
3374    // flat melee damage without resistence/etc reduction
3375    if(!schoolStr)
3376    {
3377        m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, SPELL_SCHOOL_MASK_NORMAL, NULL, false);
3378        m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, SPELL_SCHOOL_MASK_NORMAL, damage, 0, 0, VICTIMSTATE_NORMAL, 0);
3379        return true;
3380    }
3381
3382    uint32 school = schoolStr ? atoi((char*)schoolStr) : SPELL_SCHOOL_NORMAL;
3383    if(school >= MAX_SPELL_SCHOOL)
3384        return false;
3385
3386    SpellSchoolMask schoolmask = SpellSchoolMask(1 << school);
3387
3388    if ( schoolmask & SPELL_SCHOOL_MASK_NORMAL )
3389        damage = m_session->GetPlayer()->CalcArmorReducedDamage(target, damage);
3390
3391    char* spellStr = strtok((char*)NULL, " ");
3392
3393    // melee damage by specific school
3394    if(!spellStr)
3395    {
3396        uint32 absorb = 0;
3397        uint32 resist = 0;
3398
3399        m_session->GetPlayer()->CalcAbsorbResist(target,schoolmask, SPELL_DIRECT_DAMAGE, damage, &absorb, &resist);
3400
3401        if (damage <= absorb + resist)
3402            return true;
3403
3404        damage -= absorb + resist;
3405
3406        m_session->GetPlayer()->DealDamage(target, damage, NULL, DIRECT_DAMAGE, schoolmask, NULL, false);
3407        m_session->GetPlayer()->SendAttackStateUpdate (HITINFO_NORMALSWING2, target, 1, schoolmask, damage, absorb, resist, VICTIMSTATE_NORMAL, 0);
3408        return true;
3409    }
3410
3411    // non-melee damage
3412
3413    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
3414    uint32 spellid = extractSpellIdFromLink((char*)args);
3415    if(!spellid || !sSpellStore.LookupEntry(spellid))
3416        return false;
3417
3418    m_session->GetPlayer()->SpellNonMeleeDamageLog(target, spellid, damage, false);
3419    return true;
3420}
3421
3422bool ChatHandler::HandleModifyArenaCommand(const char * args)
3423{
3424    if (!*args)
3425        return false;
3426
3427    Player *target = getSelectedPlayer();
3428    if(!target)
3429    {
3430        SendSysMessage(LANG_PLAYER_NOT_FOUND);
3431        SetSentErrorMessage(true);
3432        return false;
3433    }
3434
3435    int32 amount = (uint32)atoi(args);
3436
3437    target->ModifyArenaPoints(amount);
3438
3439    PSendSysMessage(LANG_COMMAND_MODIFY_ARENA, target->GetName(), target->GetArenaPoints());
3440
3441    return true;
3442}
3443
3444bool ChatHandler::HandleReviveCommand(const char* args)
3445{
3446    Player* SelectedPlayer = NULL;
3447
3448    if (*args)
3449    {
3450        std::string name = args;
3451        if(!normalizePlayerName(name))
3452        {
3453            SendSysMessage(LANG_PLAYER_NOT_FOUND);
3454            SetSentErrorMessage(true);
3455            return false;
3456        }
3457
3458        SelectedPlayer = objmgr.GetPlayer(name.c_str());
3459    }
3460    else
3461        SelectedPlayer = getSelectedPlayer();
3462
3463    if(!SelectedPlayer)
3464    {
3465        SendSysMessage(LANG_NO_CHAR_SELECTED);
3466        SetSentErrorMessage(true);
3467        return false;
3468    }
3469
3470    SelectedPlayer->ResurrectPlayer(0.5f);
3471    SelectedPlayer->SpawnCorpseBones();
3472    SelectedPlayer->SaveToDB();
3473    return true;
3474}
3475
3476bool ChatHandler::HandleAuraCommand(const char* args)
3477{
3478    char* px = strtok((char*)args, " ");
3479    if (!px)
3480        return false;
3481
3482    Unit *target = getSelectedUnit();
3483    if(!target)
3484    {
3485        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3486        SetSentErrorMessage(true);
3487        return false;
3488    }
3489
3490    uint32 spellID = (uint32)atoi(px);
3491    SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
3492    if(spellInfo)
3493    {
3494        for(uint32 i = 0;i<3;i++)
3495        {
3496            uint8 eff = spellInfo->Effect[i];
3497            if (eff>=TOTAL_SPELL_EFFECTS)
3498                continue;
3499            if( IsAreaAuraEffect(eff)           ||
3500                eff == SPELL_EFFECT_APPLY_AURA  ||
3501                eff == SPELL_EFFECT_PERSISTENT_AREA_AURA )
3502            {
3503                Aura *Aur = CreateAura(spellInfo, i, NULL, target);
3504                target->AddAura(Aur);
3505            }
3506        }
3507    }
3508
3509    return true;
3510}
3511
3512bool ChatHandler::HandleUnAuraCommand(const char* args)
3513{
3514    char* px = strtok((char*)args, " ");
3515    if (!px)
3516        return false;
3517
3518    Unit *target = getSelectedUnit();
3519    if(!target)
3520    {
3521        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
3522        SetSentErrorMessage(true);
3523        return false;
3524    }
3525
3526    std::string argstr = args;
3527    if (argstr == "all")
3528    {
3529        target->RemoveAllAuras();
3530        return true;
3531    }
3532
3533    uint32 spellID = (uint32)atoi(px);
3534    target->RemoveAurasDueToSpell(spellID);
3535
3536    return true;
3537}
3538
3539bool ChatHandler::HandleLinkGraveCommand(const char* args)
3540{
3541    if(!*args)
3542        return false;
3543
3544    char* px = strtok((char*)args, " ");
3545    if (!px)
3546        return false;
3547
3548    uint32 g_id = (uint32)atoi(px);
3549
3550    uint32 g_team;
3551
3552    char* px2 = strtok(NULL, " ");
3553
3554    if (!px2)
3555        g_team = 0;
3556    else if (strncmp(px2,"horde",6)==0)
3557        g_team = HORDE;
3558    else if (strncmp(px2,"alliance",9)==0)
3559        g_team = ALLIANCE;
3560    else
3561        return false;
3562
3563    WorldSafeLocsEntry const* graveyard =  sWorldSafeLocsStore.LookupEntry(g_id);
3564
3565    if(!graveyard )
3566    {
3567        PSendSysMessage(LANG_COMMAND_GRAVEYARDNOEXIST, g_id);
3568        SetSentErrorMessage(true);
3569        return false;
3570    }
3571
3572    Player* player = m_session->GetPlayer();
3573
3574    uint32 zoneId = player->GetZoneId();
3575
3576    AreaTableEntry const *areaEntry = GetAreaEntryByAreaID(zoneId);
3577    if(!areaEntry || areaEntry->zone !=0 )
3578    {
3579        PSendSysMessage(LANG_COMMAND_GRAVEYARDWRONGZONE, g_id,zoneId);
3580        SetSentErrorMessage(true);
3581        return false;
3582    }
3583
3584    if(graveyard->map_id != areaEntry->mapid && g_team != 0)
3585    {
3586        SendSysMessage(LANG_COMMAND_GRAVEYARDWRONGTEAM);
3587        SetSentErrorMessage(true);
3588        return false;
3589    }
3590
3591    if(objmgr.AddGraveYardLink(g_id,player->GetZoneId(),g_team))
3592        PSendSysMessage(LANG_COMMAND_GRAVEYARDLINKED, g_id,zoneId);
3593    else
3594        PSendSysMessage(LANG_COMMAND_GRAVEYARDALRLINKED, g_id,zoneId);
3595
3596    return true;
3597}
3598
3599bool ChatHandler::HandleNearGraveCommand(const char* args)
3600{
3601    uint32 g_team;
3602
3603    size_t argslen = strlen(args);
3604
3605    if(!*args)
3606        g_team = 0;
3607    else if (strncmp((char*)args,"horde",argslen)==0)
3608        g_team = HORDE;
3609    else if (strncmp((char*)args,"alliance",argslen)==0)
3610        g_team = ALLIANCE;
3611    else
3612        return false;
3613
3614    Player* player = m_session->GetPlayer();
3615
3616    WorldSafeLocsEntry const* graveyard = objmgr.GetClosestGraveYard(
3617        player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(),player->GetMapId(),g_team);
3618
3619    if(graveyard)
3620    {
3621        uint32 g_id = graveyard->ID;
3622
3623        GraveYardData const* data = objmgr.FindGraveYardData(g_id,player->GetZoneId());
3624        if (!data)
3625        {
3626            PSendSysMessage(LANG_COMMAND_GRAVEYARDERROR,g_id);
3627            SetSentErrorMessage(true);
3628            return false;
3629        }
3630
3631        g_team = data->team;
3632
3633        std::string team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_NOTEAM);
3634
3635        if(g_team == 0)
3636            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_ANY);
3637        else if(g_team == HORDE)
3638            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_HORDE);
3639        else if(g_team == ALLIANCE)
3640            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3641
3642        PSendSysMessage(LANG_COMMAND_GRAVEYARDNEAREST, g_id,team_name.c_str(),player->GetZoneId());
3643    }
3644    else
3645    {
3646        std::string team_name;
3647
3648        if(g_team == 0)
3649            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_ANY);
3650        else if(g_team == HORDE)
3651            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_HORDE);
3652        else if(g_team == ALLIANCE)
3653            team_name = GetTrinityString(LANG_COMMAND_GRAVEYARD_ALLIANCE);
3654
3655        if(g_team == ~uint32(0))
3656            PSendSysMessage(LANG_COMMAND_ZONENOGRAVEYARDS, player->GetZoneId());
3657        else
3658            PSendSysMessage(LANG_COMMAND_ZONENOGRAFACTION, player->GetZoneId(),team_name.c_str());
3659    }
3660
3661    return true;
3662}
3663
3664//play npc emote
3665bool ChatHandler::HandleNpcPlayEmoteCommand(const char* args)
3666{
3667    uint32 emote = atoi((char*)args);
3668
3669    Creature* target = getSelectedCreature();
3670    if(!target)
3671    {
3672        SendSysMessage(LANG_SELECT_CREATURE);
3673        SetSentErrorMessage(true);
3674        return false;
3675    }
3676
3677    target->SetUInt32Value(UNIT_NPC_EMOTESTATE,emote);
3678
3679    return true;
3680}
3681
3682bool ChatHandler::HandleNpcInfoCommand(const char* /*args*/)
3683{
3684    Creature* target = getSelectedCreature();
3685
3686    if(!target)
3687    {
3688        SendSysMessage(LANG_SELECT_CREATURE);
3689        SetSentErrorMessage(true);
3690        return false;
3691    }
3692
3693    uint32 faction = target->getFaction();
3694    uint32 npcflags = target->GetUInt32Value(UNIT_NPC_FLAGS);
3695    uint32 displayid = target->GetDisplayId();
3696    uint32 nativeid = target->GetNativeDisplayId();
3697    uint32 Entry = target->GetEntry();
3698    CreatureInfo const* cInfo = target->GetCreatureInfo();
3699
3700    int32 curRespawnDelay = target->GetRespawnTimeEx()-time(NULL);
3701    if(curRespawnDelay < 0)
3702        curRespawnDelay = 0;
3703    std::string curRespawnDelayStr = secsToTimeString(curRespawnDelay,true);
3704    std::string defRespawnDelayStr = secsToTimeString(target->GetRespawnDelay(),true);
3705
3706    PSendSysMessage(LANG_NPCINFO_CHAR,  target->GetDBTableGUIDLow(), faction, npcflags, Entry, displayid, nativeid);
3707    PSendSysMessage(LANG_NPCINFO_LEVEL, target->getLevel());
3708    PSendSysMessage(LANG_NPCINFO_HEALTH,target->GetCreateHealth(), target->GetMaxHealth(), target->GetHealth());
3709    PSendSysMessage(LANG_NPCINFO_FLAGS, target->GetUInt32Value(UNIT_FIELD_FLAGS), target->GetUInt32Value(UNIT_DYNAMIC_FLAGS), target->getFaction());
3710    PSendSysMessage(LANG_COMMAND_RAWPAWNTIMES, defRespawnDelayStr.c_str(),curRespawnDelayStr.c_str());
3711    PSendSysMessage(LANG_NPCINFO_LOOT,  cInfo->lootid,cInfo->pickpocketLootId,cInfo->SkinLootId);
3712    PSendSysMessage(LANG_NPCINFO_DUNGEON_ID, target->GetInstanceId());
3713    PSendSysMessage(LANG_NPCINFO_POSITION,float(target->GetPositionX()), float(target->GetPositionY()), float(target->GetPositionZ()));
3714
3715    if ((npcflags & UNIT_NPC_FLAG_VENDOR) )
3716    {
3717        SendSysMessage(LANG_NPCINFO_VENDOR);
3718    }
3719    if ((npcflags & UNIT_NPC_FLAG_TRAINER) )
3720    {
3721        SendSysMessage(LANG_NPCINFO_TRAINER);
3722    }
3723
3724    return true;
3725}
3726
3727bool ChatHandler::HandleExploreCheatCommand(const char* args)
3728{
3729    if (!*args)
3730        return false;
3731
3732    int flag = atoi((char*)args);
3733
3734    Player *chr = getSelectedPlayer();
3735    if (chr == NULL)
3736    {
3737        SendSysMessage(LANG_NO_CHAR_SELECTED);
3738        SetSentErrorMessage(true);
3739        return false;
3740    }
3741
3742    if (flag != 0)
3743    {
3744        PSendSysMessage(LANG_YOU_SET_EXPLORE_ALL, chr->GetName());
3745        if (needReportToTarget(chr))
3746            ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_ALL,GetName());
3747    }
3748    else
3749    {
3750        PSendSysMessage(LANG_YOU_SET_EXPLORE_NOTHING, chr->GetName());
3751        if (needReportToTarget(chr))
3752            ChatHandler(chr).PSendSysMessage(LANG_YOURS_EXPLORE_SET_NOTHING,GetName());
3753    }
3754
3755    for (uint8 i=0; i<128; i++)
3756    {
3757        if (flag != 0)
3758        {
3759            m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0xFFFFFFFF);
3760        }
3761        else
3762        {
3763            m_session->GetPlayer()->SetFlag(PLAYER_EXPLORED_ZONES_1+i,0);
3764        }
3765    }
3766
3767    return true;
3768}
3769
3770bool ChatHandler::HandleHoverCommand(const char* args)
3771{
3772    char* px = strtok((char*)args, " ");
3773    uint32 flag;
3774    if (!px)
3775        flag = 1;
3776    else
3777        flag = atoi(px);
3778
3779    m_session->GetPlayer()->SetHover(flag);
3780
3781    if (flag)
3782        SendSysMessage(LANG_HOVER_ENABLED);
3783    else
3784        SendSysMessage(LANG_HOVER_DISABLED);
3785
3786    return true;
3787}
3788
3789bool ChatHandler::HandleWaterwalkCommand(const char* args)
3790{
3791    if(!args)
3792        return false;
3793
3794    Player *player = getSelectedPlayer();
3795    if(!player)
3796    {
3797        PSendSysMessage(LANG_NO_CHAR_SELECTED);
3798        SetSentErrorMessage(true);
3799        return false;
3800    }
3801
3802    if (strncmp(args, "on", 3) == 0)
3803        player->SetMovement(MOVE_WATER_WALK);               // ON
3804    else if (strncmp(args, "off", 4) == 0)
3805        player->SetMovement(MOVE_LAND_WALK);                // OFF
3806    else
3807    {
3808        SendSysMessage(LANG_USE_BOL);
3809        return false;
3810    }
3811
3812    PSendSysMessage(LANG_YOU_SET_WATERWALK, args, player->GetName());
3813    if(needReportToTarget(player))
3814        ChatHandler(player).PSendSysMessage(LANG_YOUR_WATERWALK_SET, args, GetName());
3815    return true;
3816
3817}
3818
3819bool ChatHandler::HandleLevelUpCommand(const char* args)
3820{
3821    char* px = strtok((char*)args, " ");
3822    char* py = strtok((char*)NULL, " ");
3823
3824    // command format parsing
3825    char* pname = (char*)NULL;
3826    int addlevel = 1;
3827
3828    if(px && py)                                            // .levelup name level
3829    {
3830        addlevel = atoi(py);
3831        pname = px;
3832    }
3833    else if(px && !py)                                      // .levelup name OR .levelup level
3834    {
3835        if(isalpha(px[0]))                                  // .levelup name
3836            pname = px;
3837        else                                                // .levelup level
3838            addlevel = atoi(px);
3839    }
3840    // else .levelup - nothing do for preparing
3841
3842    // player
3843    Player *chr = NULL;
3844    uint64 chr_guid = 0;
3845
3846    std::string name;
3847
3848    if(pname)                                               // player by name
3849    {
3850        name = pname;
3851        if(!normalizePlayerName(name))
3852        {
3853            SendSysMessage(LANG_PLAYER_NOT_FOUND);
3854            SetSentErrorMessage(true);
3855            return false;
3856        }
3857
3858        chr = objmgr.GetPlayer(name.c_str());
3859        if(!chr)                                            // not in game
3860        {
3861            chr_guid = objmgr.GetPlayerGUIDByName(name);
3862            if (chr_guid == 0)
3863            {
3864                SendSysMessage(LANG_PLAYER_NOT_FOUND);
3865                SetSentErrorMessage(true);
3866                return false;
3867            }
3868        }
3869    }
3870    else                                                    // player by selection
3871    {
3872        chr = getSelectedPlayer();
3873
3874        if (chr == NULL)
3875        {
3876            SendSysMessage(LANG_NO_CHAR_SELECTED);
3877            SetSentErrorMessage(true);
3878            return false;
3879        }
3880
3881        name = chr->GetName();
3882    }
3883
3884    assert(chr || chr_guid);
3885
3886    int32 oldlevel = chr ? chr->getLevel() : Player::GetUInt32ValueFromDB(UNIT_FIELD_LEVEL,chr_guid);
3887    int32 newlevel = oldlevel + addlevel;
3888    if(newlevel < 1)
3889        newlevel = 1;
3890    if(newlevel > 255)                                      // hardcoded maximum level
3891        newlevel = 255;
3892
3893    if(chr)
3894    {
3895        chr->GiveLevel(newlevel);
3896        chr->InitTalentForLevel();
3897        chr->SetUInt32Value(PLAYER_XP,0);
3898
3899        if(oldlevel == newlevel)
3900            ChatHandler(chr).SendSysMessage(LANG_YOURS_LEVEL_PROGRESS_RESET);
3901        else
3902        if(oldlevel < newlevel)
3903            ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_UP,newlevel-oldlevel);
3904        else
3905        if(oldlevel > newlevel)
3906            ChatHandler(chr).PSendSysMessage(LANG_YOURS_LEVEL_DOWN,newlevel-oldlevel);
3907    }
3908    else
3909    {
3910        // update level and XP at level, all other will be updated at loading
3911        Tokens values;
3912        Player::LoadValuesArrayFromDB(values,chr_guid);
3913        Player::SetUInt32ValueInArray(values,UNIT_FIELD_LEVEL,newlevel);
3914        Player::SetUInt32ValueInArray(values,PLAYER_XP,0);
3915        Player::SaveValuesArrayInDB(values,chr_guid);
3916    }
3917
3918    if(m_session->GetPlayer() != chr)                       // including chr==NULL
3919        PSendSysMessage(LANG_YOU_CHANGE_LVL,name.c_str(),newlevel);
3920    return true;
3921}
3922
3923bool ChatHandler::HandleShowAreaCommand(const char* args)
3924{
3925    if (!*args)
3926        return false;
3927
3928    int area = atoi((char*)args);
3929
3930    Player *chr = getSelectedPlayer();
3931    if (chr == NULL)
3932    {
3933        SendSysMessage(LANG_NO_CHAR_SELECTED);
3934        SetSentErrorMessage(true);
3935        return false;
3936    }
3937
3938    int offset = area / 32;
3939    uint32 val = (uint32)(1 << (area % 32));
3940
3941    if(offset >= 128)
3942    {
3943        SendSysMessage(LANG_BAD_VALUE);
3944        SetSentErrorMessage(true);
3945        return false;
3946    }
3947
3948    uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3949    chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields | val));
3950
3951    SendSysMessage(LANG_EXPLORE_AREA);
3952    return true;
3953}
3954
3955bool ChatHandler::HandleHideAreaCommand(const char* args)
3956{
3957    if (!*args)
3958        return false;
3959
3960    int area = atoi((char*)args);
3961
3962    Player *chr = getSelectedPlayer();
3963    if (chr == NULL)
3964    {
3965        SendSysMessage(LANG_NO_CHAR_SELECTED);
3966        SetSentErrorMessage(true);
3967        return false;
3968    }
3969
3970    int offset = area / 32;
3971    uint32 val = (uint32)(1 << (area % 32));
3972
3973    if(offset >= 128)
3974    {
3975        SendSysMessage(LANG_BAD_VALUE);
3976        SetSentErrorMessage(true);
3977        return false;
3978    }
3979
3980    uint32 currFields = chr->GetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset);
3981    chr->SetUInt32Value(PLAYER_EXPLORED_ZONES_1 + offset, (uint32)(currFields ^ val));
3982
3983    SendSysMessage(LANG_UNEXPLORE_AREA);
3984    return true;
3985}
3986
3987bool ChatHandler::HandleUpdate(const char* args)
3988{
3989    if(!*args)
3990        return false;
3991
3992    uint32 updateIndex;
3993    uint32 value;
3994
3995    char* pUpdateIndex = strtok((char*)args, " ");
3996
3997    Unit* chr = getSelectedUnit();
3998    if (chr == NULL)
3999    {
4000        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4001        SetSentErrorMessage(true);
4002        return false;
4003    }
4004
4005    if(!pUpdateIndex)
4006    {
4007        return true;
4008    }
4009    updateIndex = atoi(pUpdateIndex);
4010    //check updateIndex
4011    if(chr->GetTypeId() == TYPEID_PLAYER)
4012    {
4013        if (updateIndex>=PLAYER_END) return true;
4014    }
4015    else
4016    {
4017        if (updateIndex>=UNIT_END) return true;
4018    }
4019
4020    char*  pvalue = strtok(NULL, " ");
4021    if (!pvalue)
4022    {
4023        value=chr->GetUInt32Value(updateIndex);
4024
4025        PSendSysMessage(LANG_UPDATE, chr->GetGUIDLow(),updateIndex,value);
4026        return true;
4027    }
4028
4029    value=atoi(pvalue);
4030
4031    PSendSysMessage(LANG_UPDATE_CHANGE, chr->GetGUIDLow(),updateIndex,value);
4032
4033    chr->SetUInt32Value(updateIndex,value);
4034
4035    return true;
4036}
4037
4038bool ChatHandler::HandleBankCommand(const char* /*args*/)
4039{
4040    m_session->SendShowBank( m_session->GetPlayer()->GetGUID() );
4041
4042    return true;
4043}
4044
4045bool ChatHandler::HandleChangeWeather(const char* args)
4046{
4047    if(!*args)
4048        return false;
4049
4050    //Weather is OFF
4051    if (!sWorld.getConfig(CONFIG_WEATHER))
4052    {
4053        SendSysMessage(LANG_WEATHER_DISABLED);
4054        SetSentErrorMessage(true);
4055        return false;
4056    }
4057
4058    //*Change the weather of a cell
4059    char* px = strtok((char*)args, " ");
4060    char* py = strtok(NULL, " ");
4061
4062    if (!px || !py)
4063        return false;
4064
4065    uint32 type = (uint32)atoi(px);                         //0 to 3, 0: fine, 1: rain, 2: snow, 3: sand
4066    float grade = (float)atof(py);                          //0 to 1, sending -1 is instand good weather
4067
4068    Player *player = m_session->GetPlayer();
4069    uint32 zoneid = player->GetZoneId();
4070
4071    Weather* wth = sWorld.FindWeather(zoneid);
4072
4073    if(!wth)
4074        wth = sWorld.AddWeather(zoneid);
4075    if(!wth)
4076    {
4077        SendSysMessage(LANG_NO_WEATHER);
4078        SetSentErrorMessage(true);
4079        return false;
4080    }
4081
4082    wth->SetWeather(WeatherType(type), grade);
4083
4084    return true;
4085}
4086
4087bool ChatHandler::HandleSetValue(const char* args)
4088{
4089    if(!*args)
4090        return false;
4091
4092    char* px = strtok((char*)args, " ");
4093    char* py = strtok(NULL, " ");
4094    char* pz = strtok(NULL, " ");
4095
4096    if (!px || !py)
4097        return false;
4098
4099    Unit* target = getSelectedUnit();
4100    if(!target)
4101    {
4102        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4103        SetSentErrorMessage(true);
4104        return false;
4105    }
4106
4107    uint64 guid = target->GetGUID();
4108
4109    uint32 Opcode = (uint32)atoi(px);
4110    if(Opcode >= target->GetValuesCount())
4111    {
4112        PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4113        return false;
4114    }
4115    uint32 iValue;
4116    float fValue;
4117    bool isint32 = true;
4118    if(pz)
4119        isint32 = (bool)atoi(pz);
4120    if(isint32)
4121    {
4122        iValue = (uint32)atoi(py);
4123        sLog.outDebug(GetTrinityString(LANG_SET_UINT), GUID_LOPART(guid), Opcode, iValue);
4124        target->SetUInt32Value( Opcode , iValue );
4125        PSendSysMessage(LANG_SET_UINT_FIELD, GUID_LOPART(guid), Opcode,iValue);
4126    }
4127    else
4128    {
4129        fValue = (float)atof(py);
4130        sLog.outDebug(GetTrinityString(LANG_SET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4131        target->SetFloatValue( Opcode , fValue );
4132        PSendSysMessage(LANG_SET_FLOAT_FIELD, GUID_LOPART(guid), Opcode,fValue);
4133    }
4134
4135    return true;
4136}
4137
4138bool ChatHandler::HandleGetValue(const char* args)
4139{
4140    if(!*args)
4141        return false;
4142
4143    char* px = strtok((char*)args, " ");
4144    char* pz = strtok(NULL, " ");
4145
4146    if (!px)
4147        return false;
4148
4149    Unit* target = getSelectedUnit();
4150    if(!target)
4151    {
4152        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4153        SetSentErrorMessage(true);
4154        return false;
4155    }
4156
4157    uint64 guid = target->GetGUID();
4158
4159    uint32 Opcode = (uint32)atoi(px);
4160    if(Opcode >= target->GetValuesCount())
4161    {
4162        PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, GUID_LOPART(guid), target->GetValuesCount());
4163        return false;
4164    }
4165    uint32 iValue;
4166    float fValue;
4167    bool isint32 = true;
4168    if(pz)
4169        isint32 = (bool)atoi(pz);
4170
4171    if(isint32)
4172    {
4173        iValue = target->GetUInt32Value( Opcode );
4174        sLog.outDebug(GetTrinityString(LANG_GET_UINT), GUID_LOPART(guid), Opcode, iValue);
4175        PSendSysMessage(LANG_GET_UINT_FIELD, GUID_LOPART(guid), Opcode,    iValue);
4176    }
4177    else
4178    {
4179        fValue = target->GetFloatValue( Opcode );
4180        sLog.outDebug(GetTrinityString(LANG_GET_FLOAT), GUID_LOPART(guid), Opcode, fValue);
4181        PSendSysMessage(LANG_GET_FLOAT_FIELD, GUID_LOPART(guid), Opcode, fValue);
4182    }
4183
4184    return true;
4185}
4186
4187bool ChatHandler::HandleSet32Bit(const char* args)
4188{
4189    if(!*args)
4190        return false;
4191
4192    char* px = strtok((char*)args, " ");
4193    char* py = strtok(NULL, " ");
4194
4195    if (!px || !py)
4196        return false;
4197
4198    uint32 Opcode = (uint32)atoi(px);
4199    uint32 Value = (uint32)atoi(py);
4200    if (Value > 32)                                         //uint32 = 32 bits
4201        return false;
4202
4203    sLog.outDebug(GetTrinityString(LANG_SET_32BIT), Opcode, Value);
4204
4205    m_session->GetPlayer( )->SetUInt32Value( Opcode , 2^Value );
4206
4207    PSendSysMessage(LANG_SET_32BIT_FIELD, Opcode,1);
4208    return true;
4209}
4210
4211bool ChatHandler::HandleMod32Value(const char* args)
4212{
4213    if(!*args)
4214        return false;
4215
4216    char* px = strtok((char*)args, " ");
4217    char* py = strtok(NULL, " ");
4218
4219    if (!px || !py)
4220        return false;
4221
4222    uint32 Opcode = (uint32)atoi(px);
4223    int Value = atoi(py);
4224
4225    if(Opcode >= m_session->GetPlayer()->GetValuesCount())
4226    {
4227        PSendSysMessage(LANG_TOO_BIG_INDEX, Opcode, m_session->GetPlayer()->GetGUIDLow(), m_session->GetPlayer( )->GetValuesCount());
4228        return false;
4229    }
4230
4231    sLog.outDebug(GetTrinityString(LANG_CHANGE_32BIT), Opcode, Value);
4232
4233    int CurrentValue = (int)m_session->GetPlayer( )->GetUInt32Value( Opcode );
4234
4235    CurrentValue += Value;
4236    m_session->GetPlayer( )->SetUInt32Value( Opcode , (uint32)CurrentValue );
4237
4238    PSendSysMessage(LANG_CHANGE_32BIT_FIELD, Opcode,CurrentValue);
4239
4240    return true;
4241}
4242
4243bool ChatHandler::HandleAddTeleCommand(const char * args)
4244{
4245    if(!*args)
4246        return false;
4247
4248    Player *player=m_session->GetPlayer();
4249    if (!player)
4250        return false;
4251
4252    std::string name = args;
4253
4254    if(objmgr.GetGameTele(name))
4255    {
4256        SendSysMessage(LANG_COMMAND_TP_ALREADYEXIST);
4257        SetSentErrorMessage(true);
4258        return false;
4259    }
4260
4261    GameTele tele;
4262    tele.position_x  = player->GetPositionX();
4263    tele.position_y  = player->GetPositionY();
4264    tele.position_z  = player->GetPositionZ();
4265    tele.orientation = player->GetOrientation();
4266    tele.mapId       = player->GetMapId();
4267    tele.name        = name;
4268
4269    if(objmgr.AddGameTele(tele))
4270    {
4271        SendSysMessage(LANG_COMMAND_TP_ADDED);
4272    }
4273    else
4274    {
4275        SendSysMessage(LANG_COMMAND_TP_ADDEDERR);
4276        SetSentErrorMessage(true);
4277        return false;
4278    }
4279
4280    return true;
4281}
4282
4283bool ChatHandler::HandleDelTeleCommand(const char * args)
4284{
4285    if(!*args)
4286        return false;
4287
4288    std::string name = args;
4289
4290    if(!objmgr.DeleteGameTele(name))
4291    {
4292        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
4293        SetSentErrorMessage(true);
4294        return false;
4295    }
4296
4297    SendSysMessage(LANG_COMMAND_TP_DELETED);
4298    return true;
4299}
4300
4301bool ChatHandler::HandleListAurasCommand (const char * /*args*/)
4302{
4303    Unit *unit = getSelectedUnit();
4304    if(!unit)
4305    {
4306        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
4307        SetSentErrorMessage(true);
4308        return false;
4309    }
4310
4311    char const* talentStr = GetTrinityString(LANG_TALENT);
4312    char const* passiveStr = GetTrinityString(LANG_PASSIVE);
4313
4314    Unit::AuraMap const& uAuras = unit->GetAuras();
4315    PSendSysMessage(LANG_COMMAND_TARGET_LISTAURAS, uAuras.size());
4316    for (Unit::AuraMap::const_iterator itr = uAuras.begin(); itr != uAuras.end(); ++itr)
4317    {
4318        bool talent = GetTalentSpellCost(itr->second->GetId()) > 0;
4319        PSendSysMessage(LANG_COMMAND_TARGET_AURADETAIL, itr->second->GetId(), itr->second->GetEffIndex(),
4320            itr->second->GetModifier()->m_auraname, itr->second->GetAuraDuration(), itr->second->GetAuraMaxDuration(),
4321            itr->second->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],
4322            (itr->second->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4323            IS_PLAYER_GUID(itr->second->GetCasterGUID()) ? "player" : "creature",GUID_LOPART(itr->second->GetCasterGUID()));
4324    }
4325    for (int i = 0; i < TOTAL_AURAS; i++)
4326    {
4327        Unit::AuraList const& uAuraList = unit->GetAurasByType(AuraType(i));
4328        if (uAuraList.empty()) continue;
4329        PSendSysMessage(LANG_COMMAND_TARGET_LISTAURATYPE, uAuraList.size(), i);
4330        for (Unit::AuraList::const_iterator itr = uAuraList.begin(); itr != uAuraList.end(); ++itr)
4331        {
4332            bool talent = GetTalentSpellCost((*itr)->GetId()) > 0;
4333            PSendSysMessage(LANG_COMMAND_TARGET_AURASIMPLE, (*itr)->GetId(), (*itr)->GetEffIndex(),
4334                (*itr)->GetSpellProto()->SpellName[m_session->GetSessionDbcLocale()],((*itr)->IsPassive() ? passiveStr : ""),(talent ? talentStr : ""),
4335                IS_PLAYER_GUID((*itr)->GetCasterGUID()) ? "player" : "creature",GUID_LOPART((*itr)->GetCasterGUID()));
4336        }
4337    }
4338    return true;
4339}
4340
4341bool ChatHandler::HandleResetHonorCommand (const char * args)
4342{
4343    char* pName = strtok((char*)args, "");
4344    Player *player = NULL;
4345    if (pName)
4346    {
4347        std::string name = pName;
4348        if(!normalizePlayerName(name))
4349        {
4350            SendSysMessage(LANG_PLAYER_NOT_FOUND);
4351            SetSentErrorMessage(true);
4352            return false;
4353        }
4354
4355        uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4356        player = objmgr.GetPlayer(guid);
4357    }
4358    else
4359        player = getSelectedPlayer();
4360
4361    if(!player)
4362    {
4363        SendSysMessage(LANG_NO_CHAR_SELECTED);
4364        return true;
4365    }
4366
4367    player->SetUInt32Value(PLAYER_FIELD_KILLS, 0);
4368    player->SetUInt32Value(PLAYER_FIELD_LIFETIME_HONORBALE_KILLS, 0);
4369    player->SetUInt32Value(PLAYER_FIELD_HONOR_CURRENCY, 0);
4370    player->SetUInt32Value(PLAYER_FIELD_TODAY_CONTRIBUTION, 0);
4371    player->SetUInt32Value(PLAYER_FIELD_YESTERDAY_CONTRIBUTION, 0);
4372
4373    return true;
4374}
4375
4376static bool HandleResetStatsOrLevelHelper(Player* player)
4377{
4378    PlayerInfo const *info = objmgr.GetPlayerInfo(player->getRace(), player->getClass());
4379    if(!info) return false;
4380
4381    ChrClassesEntry const* cEntry = sChrClassesStore.LookupEntry(player->getClass());
4382    if(!cEntry)
4383    {
4384        sLog.outError("Class %u not found in DBC (Wrong DBC files?)",player->getClass());
4385        return false;
4386    }
4387
4388    uint8 powertype = cEntry->powerType;
4389
4390    uint32 unitfield;
4391    if(powertype == POWER_RAGE)
4392        unitfield = 0x1100EE00;
4393    else if(powertype == POWER_ENERGY)
4394        unitfield = 0x00000000;
4395    else if(powertype == POWER_MANA)
4396        unitfield = 0x0000EE00;
4397    else
4398    {
4399        sLog.outError("Invalid default powertype %u for player (class %u)",powertype,player->getClass());
4400        return false;
4401    }
4402
4403    // reset m_form if no aura
4404    if(!player->HasAuraType(SPELL_AURA_MOD_SHAPESHIFT))
4405        player->m_form = FORM_NONE;
4406
4407    player->SetFloatValue(UNIT_FIELD_BOUNDINGRADIUS, DEFAULT_WORLD_OBJECT_SIZE );
4408    player->SetFloatValue(UNIT_FIELD_COMBATREACH, 1.5f   );
4409
4410    player->setFactionForRace(player->getRace());
4411
4412    player->SetUInt32Value(UNIT_FIELD_BYTES_0, ( ( player->getRace() ) | ( player->getClass() << 8 ) | ( player->getGender() << 16 ) | ( powertype << 24 ) ) );
4413
4414    // reset only if player not in some form;
4415    if(player->m_form==FORM_NONE)
4416    {
4417        switch(player->getGender())
4418        {
4419            case GENDER_FEMALE:
4420                player->SetDisplayId(info->displayId_f);
4421                player->SetNativeDisplayId(info->displayId_f);
4422                break;
4423            case GENDER_MALE:
4424                player->SetDisplayId(info->displayId_m);
4425                player->SetNativeDisplayId(info->displayId_m);
4426                break;
4427            default:
4428                break;
4429        }
4430    }
4431
4432    // set UNIT_FIELD_BYTES_1 to init state but preserve m_form value
4433    player->SetUInt32Value(UNIT_FIELD_BYTES_1, unitfield);
4434    player->SetByteValue(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_UNK3 | UNIT_BYTE2_FLAG_UNK5 );
4435    player->SetByteValue(UNIT_FIELD_BYTES_2, 3, player->m_form);
4436
4437    player->SetUInt32Value(UNIT_FIELD_FLAGS, UNIT_FLAG_PVP_ATTACKABLE);
4438
4439    //-1 is default value
4440    player->SetUInt32Value(PLAYER_FIELD_WATCHED_FACTION_INDEX, uint32(-1));
4441
4442    //player->SetUInt32Value(PLAYER_FIELD_BYTES, 0xEEE00000 );
4443    return true;
4444}
4445
4446bool ChatHandler::HandleResetLevelCommand(const char * args)
4447{
4448    char* pName = strtok((char*)args, "");
4449    Player *player = NULL;
4450    if (pName)
4451    {
4452        std::string name = pName;
4453        if(!normalizePlayerName(name))
4454        {
4455            SendSysMessage(LANG_PLAYER_NOT_FOUND);
4456            SetSentErrorMessage(true);
4457            return false;
4458        }
4459
4460        uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4461        player = objmgr.GetPlayer(guid);
4462    }
4463    else
4464        player = getSelectedPlayer();
4465
4466    if(!player)
4467    {
4468        SendSysMessage(LANG_NO_CHAR_SELECTED);
4469        SetSentErrorMessage(true);
4470        return false;
4471    }
4472
4473    if(!HandleResetStatsOrLevelHelper(player))
4474        return false;
4475
4476    player->SetLevel(1);
4477    player->InitStatsForLevel(true);
4478    player->InitTaxiNodesForLevel();
4479    player->InitTalentForLevel();
4480    player->SetUInt32Value(PLAYER_XP,0);
4481
4482    // reset level to summoned pet
4483    Pet* pet = player->GetPet();
4484    if(pet && pet->getPetType()==SUMMON_PET)
4485        pet->InitStatsForLevel(1);
4486
4487    return true;
4488}
4489
4490bool ChatHandler::HandleResetStatsCommand(const char * args)
4491{
4492    char* pName = strtok((char*)args, "");
4493    Player *player = NULL;
4494    if (pName)
4495    {
4496        std::string name = pName;
4497        if(!normalizePlayerName(name))
4498        {
4499            SendSysMessage(LANG_PLAYER_NOT_FOUND);
4500            SetSentErrorMessage(true);
4501            return false;
4502        }
4503
4504        uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str());
4505        player = objmgr.GetPlayer(guid);
4506    }
4507    else
4508        player = getSelectedPlayer();
4509
4510    if(!player)
4511    {
4512        SendSysMessage(LANG_NO_CHAR_SELECTED);
4513        SetSentErrorMessage(true);
4514        return false;
4515    }
4516
4517    if(!HandleResetStatsOrLevelHelper(player))
4518        return false;
4519
4520    player->InitStatsForLevel(true);
4521    player->InitTaxiNodesForLevel();
4522    player->InitTalentForLevel();
4523
4524    return true;
4525}
4526
4527bool ChatHandler::HandleResetSpellsCommand(const char * args)
4528{
4529    char* pName = strtok((char*)args, "");
4530    Player *player = NULL;
4531    uint64 playerGUID = 0;
4532    if (pName)
4533    {
4534        std::string name = pName;
4535
4536        if(!normalizePlayerName(name))
4537        {
4538            SendSysMessage(LANG_PLAYER_NOT_FOUND);
4539            SetSentErrorMessage(true);
4540            return false;
4541        }
4542
4543        player = objmgr.GetPlayer(name.c_str());
4544        if(!player)
4545            playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4546    }
4547    else
4548        player = getSelectedPlayer();
4549
4550    if(!player && !playerGUID)
4551    {
4552        SendSysMessage(LANG_NO_CHAR_SELECTED);
4553        SetSentErrorMessage(true);
4554        return false;
4555    }
4556
4557    if(player)
4558    {
4559        player->resetSpells();
4560
4561        ChatHandler(player).SendSysMessage(LANG_RESET_SPELLS);
4562
4563        if(m_session->GetPlayer()!=player)
4564            PSendSysMessage(LANG_RESET_SPELLS_ONLINE,player->GetName());
4565    }
4566    else
4567    {
4568        CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_SPELLS), GUID_LOPART(playerGUID));
4569        PSendSysMessage(LANG_RESET_SPELLS_OFFLINE,pName);
4570    }
4571
4572    return true;
4573}
4574
4575bool ChatHandler::HandleResetTalentsCommand(const char * args)
4576{
4577    char* pName = strtok((char*)args, "");
4578    Player *player = NULL;
4579    uint64 playerGUID = 0;
4580    if (pName)
4581    {
4582        std::string name = pName;
4583        if(!normalizePlayerName(name))
4584        {
4585            SendSysMessage(LANG_PLAYER_NOT_FOUND);
4586            SetSentErrorMessage(true);
4587            return false;
4588        }
4589
4590        player = objmgr.GetPlayer(name.c_str());
4591        if(!player)
4592            playerGUID = objmgr.GetPlayerGUIDByName(name.c_str());
4593    }
4594    else
4595        player = getSelectedPlayer();
4596
4597    if(!player && !playerGUID)
4598    {
4599        SendSysMessage(LANG_NO_CHAR_SELECTED);
4600        SetSentErrorMessage(true);
4601        return false;
4602    }
4603
4604    if(player)
4605    {
4606        player->resetTalents(true);
4607
4608        ChatHandler(player).SendSysMessage(LANG_RESET_TALENTS);
4609
4610        if(m_session->GetPlayer()!=player)
4611            PSendSysMessage(LANG_RESET_TALENTS_ONLINE,player->GetName());
4612    }
4613    else
4614    {
4615        CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u' WHERE guid = '%u'",uint32(AT_LOGIN_RESET_TALENTS), GUID_LOPART(playerGUID) );
4616        PSendSysMessage(LANG_RESET_TALENTS_OFFLINE,pName);
4617    }
4618
4619    return true;
4620}
4621
4622bool ChatHandler::HandleResetAllCommand(const char * args)
4623{
4624    if(!*args)
4625        return false;
4626
4627    std::string casename = args;
4628
4629    AtLoginFlags atLogin;
4630
4631    // Command specially created as single command to prevent using short case names
4632    if(casename=="spells")
4633    {
4634        atLogin = AT_LOGIN_RESET_SPELLS;
4635        sWorld.SendWorldText(LANG_RESETALL_SPELLS);
4636    }
4637    else if(casename=="talents")
4638    {
4639        atLogin = AT_LOGIN_RESET_TALENTS;
4640        sWorld.SendWorldText(LANG_RESETALL_TALENTS);
4641    }
4642    else
4643    {
4644        PSendSysMessage(LANG_RESETALL_UNKNOWN_CASE,args);
4645        SetSentErrorMessage(true);
4646        return false;
4647    }
4648
4649    CharacterDatabase.PExecute("UPDATE characters SET at_login = at_login | '%u'",atLogin);
4650    HashMapHolder<Player>::MapType const& plist = ObjectAccessor::Instance().GetPlayers();
4651    for(HashMapHolder<Player>::MapType::const_iterator itr = plist.begin(); itr != plist.end(); ++itr)
4652        itr->second->SetAtLoginFlag(atLogin);
4653
4654    return true;
4655}
4656
4657bool ChatHandler::HandleShutDownCommand(const char* args)
4658{
4659    if(!*args)
4660        return false;
4661
4662    if(std::string(args)=="cancel")
4663    {
4664        sWorld.ShutdownCancel();
4665    }
4666    else
4667    {
4668        int32 time = atoi(args);
4669
4670        ///- Prevent interpret wrong arg value as 0 secs shutdown time
4671        if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4672            return false;
4673
4674        sWorld.ShutdownServ(time);
4675    }
4676    return true;
4677}
4678
4679bool ChatHandler::HandleRestartCommand(const char* args)
4680{
4681    if(!*args)
4682        return false;
4683
4684    if(std::string(args)=="cancel")
4685    {
4686        sWorld.ShutdownCancel();
4687    }
4688    else
4689    {
4690        int32 time = atoi(args);
4691
4692        ///- Prevent interpret wrong arg value as 0 secs shutdown time
4693        if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4694            return false;
4695
4696        sWorld.ShutdownServ(time, SHUTDOWN_MASK_RESTART);
4697    }
4698    return true;
4699}
4700
4701bool ChatHandler::HandleIdleRestartCommand(const char* args)
4702{
4703    if(!*args)
4704        return false;
4705
4706    if(std::string(args)=="cancel")
4707    {
4708        sWorld.ShutdownCancel();
4709    }
4710    else
4711    {
4712        int32 time = atoi(args);
4713
4714        ///- Prevent interpret wrong arg value as 0 secs shutdown time
4715        if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4716            return false;
4717
4718        sWorld.ShutdownServ(time,SHUTDOWN_MASK_RESTART+SHUTDOWN_MASK_IDLE);
4719    }
4720    return true;
4721}
4722
4723bool ChatHandler::HandleIdleShutDownCommand(const char* args)
4724{
4725    if(!*args)
4726        return false;
4727
4728    if(std::string(args)=="cancel")
4729    {
4730        sWorld.ShutdownCancel();
4731    }
4732    else
4733    {
4734        int32 time = atoi(args);
4735
4736        ///- Prevent interpret wrong arg value as 0 secs shutdown time
4737        if(time == 0 && (args[0]!='0' || args[1]!='\0') || time < 0)
4738            return false;
4739
4740        sWorld.ShutdownServ(time,SHUTDOWN_MASK_IDLE);
4741    }
4742    return true;
4743}
4744
4745bool ChatHandler::HandleAddQuest(const char* args)
4746{
4747    Player* player = getSelectedPlayer();
4748    if(!player)
4749    {
4750        SendSysMessage(LANG_NO_CHAR_SELECTED);
4751        SetSentErrorMessage(true);
4752        return false;
4753    }
4754
4755    // .addquest #entry'
4756    // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4757    char* cId = extractKeyFromLink((char*)args,"Hquest");
4758    if(!cId)
4759        return false;
4760
4761    uint32 entry = atol(cId);
4762
4763    Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4764
4765    if(!pQuest)
4766    {
4767        PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND,entry);
4768        SetSentErrorMessage(true);
4769        return false;
4770    }
4771
4772    // check item starting quest (it can work incorrectly if added without item in inventory)
4773    for (uint32 id = 0; id < sItemStorage.MaxEntry; id++)
4774    {
4775        ItemPrototype const *pProto = sItemStorage.LookupEntry<ItemPrototype>(id);
4776        if (!pProto)
4777            continue;
4778
4779        if (pProto->StartQuest == entry)
4780        {
4781            PSendSysMessage(LANG_COMMAND_QUEST_STARTFROMITEM, entry, pProto->ItemId);
4782            SetSentErrorMessage(true);
4783            return false;
4784        }
4785    }
4786
4787    // ok, normal (creature/GO starting) quest
4788    if( player->CanAddQuest( pQuest, true ) )
4789    {
4790        player->AddQuest( pQuest, NULL );
4791
4792        if ( player->CanCompleteQuest( entry ) )
4793            player->CompleteQuest( entry );
4794    }
4795
4796    return true;
4797}
4798
4799bool ChatHandler::HandleRemoveQuest(const char* args)
4800{
4801    Player* player = getSelectedPlayer();
4802    if(!player)
4803    {
4804        SendSysMessage(LANG_NO_CHAR_SELECTED);
4805        SetSentErrorMessage(true);
4806        return false;
4807    }
4808
4809    // .removequest #entry'
4810    // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4811    char* cId = extractKeyFromLink((char*)args,"Hquest");
4812    if(!cId)
4813        return false;
4814
4815    uint32 entry = atol(cId);
4816
4817    Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4818
4819    if(!pQuest)
4820    {
4821        PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4822        SetSentErrorMessage(true);
4823        return false;
4824    }
4825
4826    // remove all quest entries for 'entry' from quest log
4827    for(uint8 slot = 0; slot < MAX_QUEST_LOG_SIZE; ++slot )
4828    {
4829        uint32 quest = player->GetQuestSlotQuestId(slot);
4830        if(quest==entry)
4831        {
4832            player->SetQuestSlot(slot,0);
4833
4834            // we ignore unequippable quest items in this case, its' still be equipped
4835            player->TakeQuestSourceItem( quest, false );
4836        }
4837    }
4838
4839    // set quest status to not started (will updated in DB at next save)
4840    player->SetQuestStatus( entry, QUEST_STATUS_NONE);
4841
4842    // reset rewarded for restart repeatable quest
4843    player->getQuestStatusMap()[entry].m_rewarded = false;
4844
4845    SendSysMessage(LANG_COMMAND_QUEST_REMOVED);
4846    return true;
4847}
4848
4849bool ChatHandler::HandleCompleteQuest(const char* args)
4850{
4851    Player* player = getSelectedPlayer();
4852    if(!player)
4853    {
4854        SendSysMessage(LANG_NO_CHAR_SELECTED);
4855        SetSentErrorMessage(true);
4856        return false;
4857    }
4858
4859    // .quest complete #entry
4860    // number or [name] Shift-click form |color|Hquest:quest_id|h[name]|h|r
4861    char* cId = extractKeyFromLink((char*)args,"Hquest");
4862    if(!cId)
4863        return false;
4864
4865    uint32 entry = atol(cId);
4866
4867    Quest const* pQuest = objmgr.GetQuestTemplate(entry);
4868
4869    // If player doesn't have the quest
4870    if(!pQuest || player->GetQuestStatus(entry) == QUEST_STATUS_NONE)
4871    {
4872        PSendSysMessage(LANG_COMMAND_QUEST_NOTFOUND, entry);
4873        SetSentErrorMessage(true);
4874        return false;
4875    }
4876
4877    // Add quest items for quests that require items
4878    for(uint8 x = 0; x < QUEST_OBJECTIVES_COUNT; ++x)
4879    {
4880        uint32 id = pQuest->ReqItemId[x];
4881        uint32 count = pQuest->ReqItemCount[x];
4882        if(!id || !count)
4883            continue;
4884
4885        uint32 curItemCount = player->GetItemCount(id,true);
4886
4887        ItemPosCountVec dest;
4888        uint8 msg = player->CanStoreNewItem( NULL_BAG, NULL_SLOT, dest, id, count-curItemCount );
4889        if( msg == EQUIP_ERR_OK )
4890        {
4891            Item* item = player->StoreNewItem( dest, id, true);
4892            player->SendNewItem(item,count-curItemCount,true,false);
4893        }
4894    }
4895
4896    // All creature/GO slain/casted (not required, but otherwise it will display "Creature slain 0/10")
4897    for(uint8 i = 0; i < QUEST_OBJECTIVES_COUNT; i++)
4898    {
4899        uint32 creature = pQuest->ReqCreatureOrGOId[i];
4900        uint32 creaturecount = pQuest->ReqCreatureOrGOCount[i];
4901
4902        if(uint32 spell_id = pQuest->ReqSpell[i])
4903        {
4904            for(uint16 z = 0; z < creaturecount; ++z)
4905                player->CastedCreatureOrGO(creature,0,spell_id);
4906        }
4907        else if(creature > 0)
4908        {
4909            for(uint16 z = 0; z < creaturecount; ++z)
4910                player->KilledMonster(creature,0);
4911        }
4912        else if(creature < 0)
4913        {
4914            for(uint16 z = 0; z < creaturecount; ++z)
4915                player->CastedCreatureOrGO(creature,0,0);
4916        }
4917    }
4918
4919    // If the quest requires reputation to complete
4920    if(uint32 repFaction = pQuest->GetRepObjectiveFaction())
4921    {
4922        uint32 repValue = pQuest->GetRepObjectiveValue();
4923        uint32 curRep = player->GetReputation(repFaction);
4924        if(curRep < repValue)
4925        {
4926            FactionEntry const *factionEntry = sFactionStore.LookupEntry(repFaction);
4927            player->SetFactionReputation(factionEntry,repValue);
4928        }
4929    }
4930
4931    // If the quest requires money
4932    int32 ReqOrRewMoney = pQuest->GetRewOrReqMoney();
4933    if(ReqOrRewMoney < 0)
4934        player->ModifyMoney(-ReqOrRewMoney);
4935
4936    player->CompleteQuest(entry);
4937    return true;
4938}
4939
4940bool ChatHandler::HandleBanAccountCommand(const char* args)
4941{
4942    return HandleBanHelper(BAN_ACCOUNT,args);
4943}
4944
4945bool ChatHandler::HandleBanCharacterCommand(const char* args)
4946{
4947    return HandleBanHelper(BAN_CHARACTER,args);
4948}
4949
4950bool ChatHandler::HandleBanIPCommand(const char* args)
4951{
4952    return HandleBanHelper(BAN_IP,args);
4953}
4954
4955bool ChatHandler::HandleBanHelper(BanMode mode, const char* args)
4956{
4957    if(!args)
4958        return false;
4959
4960    char* cnameOrIP = strtok ((char*)args, " ");
4961    if (!cnameOrIP)
4962        return false;
4963
4964    std::string nameOrIP = cnameOrIP;
4965
4966    char* duration = strtok (NULL," ");
4967    if(!duration || !atoi(duration))
4968        return false;
4969
4970    char* reason = strtok (NULL,"");
4971    if(!reason)
4972        return false;
4973
4974    switch(mode)
4975    {
4976        case BAN_ACCOUNT:
4977            if(!AccountMgr::normilizeString(nameOrIP))
4978            {
4979                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
4980                SetSentErrorMessage(true);
4981                return false;
4982            }
4983            break;
4984        case BAN_CHARACTER:
4985            if(!normalizePlayerName(nameOrIP))
4986            {
4987                SendSysMessage(LANG_PLAYER_NOT_FOUND);
4988                SetSentErrorMessage(true);
4989                return false;
4990            }
4991            break;
4992        case BAN_IP:
4993            if(!IsIPAddress(nameOrIP.c_str()))
4994                return false;
4995            break;
4996    }
4997
4998    switch(sWorld.BanAccount(mode, nameOrIP, duration, reason,m_session ? m_session->GetPlayerName() : ""))
4999    {
5000        case BAN_SUCCESS:
5001            if(atoi(duration)>0)
5002                PSendSysMessage(LANG_BAN_YOUBANNED,nameOrIP.c_str(),secsToTimeString(TimeStringToSecs(duration),true).c_str(),reason);
5003            else
5004                PSendSysMessage(LANG_BAN_YOUPERMBANNED,nameOrIP.c_str(),reason);
5005            break;
5006        case BAN_SYNTAX_ERROR:
5007            return false;
5008        case BAN_NOTFOUND:
5009            switch(mode)
5010            {
5011                default:
5012                    PSendSysMessage(LANG_BAN_NOTFOUND,"account",nameOrIP.c_str());
5013                    break;
5014                case BAN_CHARACTER:
5015                    PSendSysMessage(LANG_BAN_NOTFOUND,"character",nameOrIP.c_str());
5016                    break;
5017                case BAN_IP:
5018                    PSendSysMessage(LANG_BAN_NOTFOUND,"ip",nameOrIP.c_str());
5019                    break;
5020            }
5021            SetSentErrorMessage(true);
5022            return false;
5023    }
5024
5025    return true;
5026}
5027
5028bool ChatHandler::HandleUnBanAccountCommand(const char* args)
5029{
5030    return HandleUnBanHelper(BAN_ACCOUNT,args);
5031}
5032
5033bool ChatHandler::HandleUnBanCharacterCommand(const char* args)
5034{
5035    return HandleUnBanHelper(BAN_CHARACTER,args);
5036}
5037
5038bool ChatHandler::HandleUnBanIPCommand(const char* args)
5039{
5040    return HandleUnBanHelper(BAN_IP,args);
5041}
5042
5043bool ChatHandler::HandleUnBanHelper(BanMode mode, const char* args)
5044{
5045    if(!args)
5046        return false;
5047
5048    char* cnameOrIP = strtok ((char*)args, " ");
5049    if(!cnameOrIP)
5050        return false;
5051
5052    std::string nameOrIP = cnameOrIP;
5053
5054    switch(mode)
5055    {
5056        case BAN_ACCOUNT:
5057            if(!AccountMgr::normilizeString(nameOrIP))
5058            {
5059                PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,nameOrIP.c_str());
5060                SetSentErrorMessage(true);
5061                return false;
5062            }
5063            break;
5064        case BAN_CHARACTER:
5065            if(!normalizePlayerName(nameOrIP))
5066            {
5067                SendSysMessage(LANG_PLAYER_NOT_FOUND);
5068                SetSentErrorMessage(true);
5069                return false;
5070            }
5071            break;
5072        case BAN_IP:
5073            if(!IsIPAddress(nameOrIP.c_str()))
5074                return false;
5075            break;
5076    }
5077
5078    if(sWorld.RemoveBanAccount(mode,nameOrIP))
5079        PSendSysMessage(LANG_UNBAN_UNBANNED,nameOrIP.c_str());
5080    else
5081        PSendSysMessage(LANG_UNBAN_ERROR,nameOrIP.c_str());
5082
5083    return true;
5084}
5085
5086bool ChatHandler::HandleBanInfoAccountCommand(const char* args)
5087{
5088    if(!args)
5089        return false;
5090
5091    char* cname = strtok((char*)args, "");
5092    if(!cname)
5093        return false;
5094
5095    std::string account_name = cname;
5096    if(!AccountMgr::normilizeString(account_name))
5097    {
5098        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5099        SetSentErrorMessage(true);
5100        return false;
5101    }
5102
5103    uint32 accountid = accmgr.GetId(account_name);
5104    if(!accountid)
5105    {
5106        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5107        return true;
5108    }
5109
5110    return HandleBanInfoHelper(accountid,account_name.c_str());
5111}
5112
5113bool ChatHandler::HandleBanInfoCharacterCommand(const char* args)
5114{
5115    if(!args)
5116        return false;
5117
5118    char* cname = strtok ((char*)args, "");
5119    if(!cname)
5120        return false;
5121
5122    std::string name = cname;
5123    if(!normalizePlayerName(name))
5124    {
5125        SendSysMessage(LANG_PLAYER_NOT_FOUND);
5126        SetSentErrorMessage(true);
5127        return false;
5128    }
5129
5130    uint32 accountid = objmgr.GetPlayerAccountIdByPlayerName(name);
5131    if(!accountid)
5132    {
5133        SendSysMessage(LANG_PLAYER_NOT_FOUND);
5134        SetSentErrorMessage(true);
5135        return false;
5136    }
5137
5138    std::string accountname;
5139    if(!accmgr.GetName(accountid,accountname))
5140    {
5141        PSendSysMessage(LANG_BANINFO_NOCHARACTER);
5142        return true;
5143    }
5144
5145    return HandleBanInfoHelper(accountid,accountname.c_str());
5146}
5147
5148bool ChatHandler::HandleBanInfoHelper(uint32 accountid, char const* accountname)
5149{
5150    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);
5151    if(!result)
5152    {
5153        PSendSysMessage(LANG_BANINFO_NOACCOUNTBAN, accountname);
5154        return true;
5155    }
5156
5157    PSendSysMessage(LANG_BANINFO_BANHISTORY,accountname);
5158    do
5159    {
5160        Field* fields = result->Fetch();
5161
5162        time_t unbandate = time_t(fields[3].GetUInt64());
5163        bool active = false;
5164        if(fields[2].GetBool() && (fields[1].GetUInt64() == (uint64)0 ||unbandate >= time(NULL)) )
5165            active = true;
5166        bool permanent = (fields[1].GetUInt64() == (uint64)0);
5167        std::string bantime = permanent?GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[1].GetUInt64(), true);
5168        PSendSysMessage(LANG_BANINFO_HISTORYENTRY,
5169            fields[0].GetString(), bantime.c_str(), active ? GetTrinityString(LANG_BANINFO_YES):GetTrinityString(LANG_BANINFO_NO), fields[4].GetString(), fields[5].GetString());
5170    }while (result->NextRow());
5171
5172    delete result;
5173    return true;
5174}
5175
5176bool ChatHandler::HandleBanInfoIPCommand(const char* args)
5177{
5178    if(!args)
5179        return false;
5180
5181    char* cIP = strtok ((char*)args, "");
5182    if(!cIP)
5183        return false;
5184
5185    if (!IsIPAddress(cIP))
5186        return false;
5187
5188    std::string IP = cIP;
5189
5190    loginDatabase.escape_string(IP);
5191    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());
5192    if(!result)
5193    {
5194        PSendSysMessage(LANG_BANINFO_NOIP);
5195        return true;
5196    }
5197
5198    Field *fields = result->Fetch();
5199    bool permanent = !fields[6].GetUInt64();
5200    PSendSysMessage(LANG_BANINFO_IPENTRY,
5201        fields[0].GetString(), fields[1].GetString(), permanent ? GetTrinityString(LANG_BANINFO_NEVER):fields[2].GetString(),
5202        permanent ? GetTrinityString(LANG_BANINFO_INFINITE):secsToTimeString(fields[3].GetUInt64(), true).c_str(), fields[4].GetString(), fields[5].GetString());
5203    delete result;
5204    return true;
5205}
5206
5207bool ChatHandler::HandleBanListCharacterCommand(const char* args)
5208{
5209    loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5210
5211    char* cFilter = strtok ((char*)args, " ");
5212    if(!cFilter)
5213        return false;
5214
5215    std::string filter = cFilter;
5216    loginDatabase.escape_string(filter);
5217    QueryResult* result = CharacterDatabase.PQuery("SELECT account FROM characters WHERE name "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'"),filter.c_str());
5218    if (!result)
5219    {
5220        PSendSysMessage(LANG_BANLIST_NOCHARACTER);
5221        return true;
5222    }
5223
5224    return HandleBanListHelper(result);
5225}
5226
5227bool ChatHandler::HandleBanListAccountCommand(const char* args)
5228{
5229    loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5230
5231    char* cFilter = strtok((char*)args, " ");
5232    std::string filter = cFilter ? cFilter : "";
5233    loginDatabase.escape_string(filter);
5234
5235    QueryResult* result;
5236
5237    if(filter.empty())
5238    {
5239        result = loginDatabase.Query("SELECT account.id, username FROM account, account_banned"
5240            " WHERE account.id = account_banned.id AND active = 1 GROUP BY account.id");
5241    }
5242    else
5243    {
5244        result = loginDatabase.PQuery("SELECT account.id, username FROM account, account_banned"
5245            " WHERE account.id = account_banned.id AND active = 1 AND username "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")" GROUP BY account.id",
5246            filter.c_str());
5247    }
5248
5249    if (!result)
5250    {
5251        PSendSysMessage(LANG_BANLIST_NOACCOUNT);
5252        return true;
5253    }
5254
5255    return HandleBanListHelper(result);
5256}
5257
5258bool ChatHandler::HandleBanListHelper(QueryResult* result)
5259{
5260    PSendSysMessage(LANG_BANLIST_MATCHINGACCOUNT);
5261
5262    // Chat short output
5263    if(m_session)
5264    {
5265        do
5266        {
5267            Field* fields = result->Fetch();
5268            uint32 accountid = fields[0].GetUInt32();
5269
5270            QueryResult* banresult = loginDatabase.PQuery("SELECT account.username FROM account,account_banned WHERE account_banned.id='%u' AND account_banned.id=account.id",accountid);
5271            if(banresult)
5272            {
5273                Field* fields2 = banresult->Fetch();
5274                PSendSysMessage("%s",fields2[0].GetString());
5275                delete banresult;
5276            }
5277        } while (result->NextRow());
5278    }
5279    // Console wide output
5280    else
5281    {
5282        SendSysMessage(LANG_BANLIST_ACCOUNTS);
5283        SendSysMessage("===============================================================================");
5284        SendSysMessage(LANG_BANLIST_ACCOUNTS_HEADER);
5285        do
5286        {
5287            SendSysMessage("-------------------------------------------------------------------------------");
5288            Field *fields = result->Fetch();
5289            uint32 account_id = fields[0].GetUInt32 ();
5290
5291            std::string account_name;
5292
5293            // "account" case, name can be get in same query
5294            if(result->GetFieldCount() > 1)
5295                account_name = fields[1].GetCppString();
5296            // "character" case, name need extract from another DB
5297            else
5298                accmgr.GetName (account_id,account_name);
5299
5300            // No SQL injection. id is uint32.
5301            QueryResult *banInfo = loginDatabase.PQuery("SELECT bandate,unbandate,bannedby,banreason FROM account_banned WHERE id = %u ORDER BY unbandate", account_id);
5302            if (banInfo)
5303            {
5304                Field *fields2 = banInfo->Fetch();
5305                do
5306                {
5307                    time_t t_ban = fields2[0].GetUInt64();
5308                    tm* aTm_ban = localtime(&t_ban);
5309
5310                    if (fields2[0].GetUInt64() == fields2[1].GetUInt64())
5311                    {
5312                        PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|   permanent  |%-15.15s|%-15.15s|",
5313                            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,
5314                            fields2[2].GetString(),fields2[3].GetString());
5315                    }
5316                    else
5317                    {
5318                        time_t t_unban = fields2[1].GetUInt64();
5319                        tm* aTm_unban = localtime(&t_unban);
5320                        PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5321                            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,
5322                            aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5323                            fields2[2].GetString(),fields2[3].GetString());
5324                    }
5325                }while ( banInfo->NextRow() );
5326                delete banInfo;
5327            }
5328        }while( result->NextRow() );
5329        SendSysMessage("===============================================================================");
5330    }
5331
5332    delete result;
5333    return true;
5334}
5335
5336bool ChatHandler::HandleBanListIPCommand(const char* args)
5337{
5338    loginDatabase.Execute("DELETE FROM ip_banned WHERE unbandate<=UNIX_TIMESTAMP() AND unbandate<>bandate");
5339
5340    char* cFilter = strtok((char*)args, " ");
5341    std::string filter = cFilter ? cFilter : "";
5342    loginDatabase.escape_string(filter);
5343
5344    QueryResult* result;
5345
5346    if(filter.empty())
5347    {
5348        result = loginDatabase.Query ("SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5349            " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP())"
5350            " ORDER BY unbandate" );
5351    }
5352    else
5353    {
5354        result = loginDatabase.PQuery( "SELECT ip,bandate,unbandate,bannedby,banreason FROM ip_banned"
5355            " WHERE (bandate=unbandate OR unbandate>UNIX_TIMESTAMP()) AND ip "_LIKE_" "_CONCAT3_("'%%'","'%s'","'%%'")
5356            " ORDER BY unbandate",filter.c_str() );
5357    }
5358
5359    if(!result)
5360    {
5361        PSendSysMessage(LANG_BANLIST_NOIP);
5362        return true;
5363    }
5364
5365    PSendSysMessage(LANG_BANLIST_MATCHINGIP);
5366    // Chat short output
5367    if(m_session)
5368    {
5369        do
5370        {
5371            Field* fields = result->Fetch();
5372            PSendSysMessage("%s",fields[0].GetString());
5373        } while (result->NextRow());
5374    }
5375    // Console wide output
5376    else
5377    {
5378        SendSysMessage(LANG_BANLIST_IPS);
5379        SendSysMessage("===============================================================================");
5380        SendSysMessage(LANG_BANLIST_IPS_HEADER);
5381        do
5382        {
5383            SendSysMessage("-------------------------------------------------------------------------------");
5384            Field *fields = result->Fetch();
5385            time_t t_ban = fields[1].GetUInt64();
5386            tm* aTm_ban = localtime(&t_ban);
5387            if ( fields[1].GetUInt64() == fields[2].GetUInt64() )
5388            {
5389                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|   permanent  |%-15.15s|%-15.15s|",
5390                    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,
5391                    fields[3].GetString(), fields[4].GetString());
5392            }
5393            else
5394            {
5395                time_t t_unban = fields[2].GetUInt64();
5396                tm* aTm_unban = localtime(&t_unban);
5397                PSendSysMessage("|%-15.15s|%02d-%02d-%02d %02d:%02d|%02d-%02d-%02d %02d:%02d|%-15.15s|%-15.15s|",
5398                    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,
5399                    aTm_unban->tm_year%100, aTm_unban->tm_mon+1, aTm_unban->tm_mday, aTm_unban->tm_hour, aTm_unban->tm_min,
5400                    fields[3].GetString(), fields[4].GetString());
5401            }
5402        }while( result->NextRow() );
5403        SendSysMessage("===============================================================================");
5404    }
5405
5406    delete result;
5407    return true;
5408}
5409
5410bool ChatHandler::HandleRespawnCommand(const char* /*args*/)
5411{
5412    Player* pl = m_session->GetPlayer();
5413
5414    // accept only explicitly selected target (not implicitly self targeting case)
5415    Unit* target = getSelectedUnit();
5416    if(pl->GetSelection() && target)
5417    {
5418        if(target->GetTypeId()!=TYPEID_UNIT)
5419        {
5420            SendSysMessage(LANG_SELECT_CREATURE);
5421            SetSentErrorMessage(true);
5422            return false;
5423        }
5424
5425        if(target->isDead())
5426            ((Creature*)target)->Respawn();
5427        return true;
5428    }
5429
5430    CellPair p(Trinity::ComputeCellPair(pl->GetPositionX(), pl->GetPositionY()));
5431    Cell cell(p);
5432    cell.data.Part.reserved = ALL_DISTRICT;
5433    cell.SetNoCreate();
5434
5435    Trinity::RespawnDo u_do;
5436    Trinity::WorldObjectWorker<Trinity::RespawnDo> worker(u_do);
5437
5438    TypeContainerVisitor<Trinity::WorldObjectWorker<Trinity::RespawnDo>, GridTypeMapContainer > obj_worker(worker);
5439    CellLock<GridReadGuard> cell_lock(cell, p);
5440    cell_lock->Visit(cell_lock, obj_worker, *MapManager::Instance().GetMap(pl->GetMapId(), pl));
5441
5442    return true;
5443}
5444
5445bool ChatHandler::HandleFlyModeCommand(const char* args)
5446{
5447    if(!args)
5448        return false;
5449
5450    Unit *unit = getSelectedUnit();
5451    if (!unit || (unit->GetTypeId() != TYPEID_PLAYER))
5452        unit = m_session->GetPlayer();
5453
5454    WorldPacket data(12);
5455    if (strncmp(args, "on", 3) == 0)
5456        data.SetOpcode(SMSG_MOVE_SET_CAN_FLY);
5457    else if (strncmp(args, "off", 4) == 0)
5458        data.SetOpcode(SMSG_MOVE_UNSET_CAN_FLY);
5459    else
5460    {
5461        SendSysMessage(LANG_USE_BOL);
5462        return false;
5463    }
5464    data.append(unit->GetPackGUID());
5465    data << uint32(0);                                      // unknown
5466    unit->SendMessageToSet(&data, true);
5467    PSendSysMessage(LANG_COMMAND_FLYMODE_STATUS, unit->GetName(), args);
5468    return true;
5469}
5470
5471bool ChatHandler::HandleLoadPDumpCommand(const char *args)
5472{
5473    if(!args)
5474        return false;
5475
5476    char * file = strtok((char*)args, " ");
5477    if(!file)
5478        return false;
5479
5480    char * account = strtok(NULL, " ");
5481    if(!account)
5482        return false;
5483
5484    std::string account_name = account;
5485    if(!AccountMgr::normilizeString(account_name))
5486    {
5487        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5488        SetSentErrorMessage(true);
5489        return false;
5490    }
5491
5492    uint32 account_id = accmgr.GetId(account_name);
5493    if(!account_id)
5494    {
5495        account_id = atoi(account);                             // use original string
5496        if(!account_id)
5497        {
5498            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5499            SetSentErrorMessage(true);
5500            return false;
5501        }
5502    }
5503
5504    if(!accmgr.GetName(account_id,account_name))
5505    {
5506        PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
5507        SetSentErrorMessage(true);
5508        return false;
5509    }
5510
5511    char* guid_str = NULL;
5512    char* name_str = strtok(NULL, " ");
5513
5514    std::string name;
5515    if(name_str)
5516    {
5517        name = name_str;
5518        // normalize the name if specified and check if it exists
5519        if(!normalizePlayerName(name))
5520        {
5521            PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5522            SetSentErrorMessage(true);
5523            return false;
5524        }
5525
5526        if(!ObjectMgr::IsValidName(name,true))
5527        {
5528            PSendSysMessage(LANG_INVALID_CHARACTER_NAME);
5529            SetSentErrorMessage(true);
5530            return false;
5531        }
5532
5533        guid_str = strtok(NULL, " ");
5534    }
5535
5536    uint32 guid = 0;
5537
5538    if(guid_str)
5539    {
5540        guid = atoi(guid_str);
5541        if(!guid)
5542        {
5543            PSendSysMessage(LANG_INVALID_CHARACTER_GUID);
5544            SetSentErrorMessage(true);
5545            return false;
5546        }
5547
5548        if(objmgr.GetPlayerAccountIdByGUID(guid))
5549        {
5550            PSendSysMessage(LANG_CHARACTER_GUID_IN_USE,guid);
5551            SetSentErrorMessage(true);
5552            return false;
5553        }
5554    }
5555
5556    switch(PlayerDumpReader().LoadDump(file, account_id, name, guid))
5557    {
5558        case DUMP_SUCCESS:
5559            PSendSysMessage(LANG_COMMAND_IMPORT_SUCCESS);
5560            break;
5561        case DUMP_FILE_OPEN_ERROR:
5562            PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5563            SetSentErrorMessage(true);
5564            return false;
5565        case DUMP_FILE_BROKEN:
5566            PSendSysMessage(LANG_DUMP_BROKEN,file);
5567            SetSentErrorMessage(true);
5568            return false;
5569        case DUMP_TOO_MANY_CHARS:
5570            PSendSysMessage(LANG_ACCOUNT_CHARACTER_LIST_FULL,account_name.c_str(),account_id);
5571            SetSentErrorMessage(true);
5572            return false;
5573        default:
5574            PSendSysMessage(LANG_COMMAND_IMPORT_FAILED);
5575            SetSentErrorMessage(true);
5576            return false;
5577    }
5578
5579    return true;
5580}
5581
5582bool ChatHandler::HandleNpcChangeEntryCommand(const char *args)
5583{
5584    if(!args)
5585        return false;
5586
5587    uint32 newEntryNum = atoi(args);
5588    if(!newEntryNum)
5589        return false;
5590
5591    Unit* unit = getSelectedUnit();
5592    if(!unit || unit->GetTypeId() != TYPEID_UNIT)
5593    {
5594        SendSysMessage(LANG_SELECT_CREATURE);
5595        SetSentErrorMessage(true);
5596        return false;
5597    }
5598    Creature* creature = (Creature*)unit;
5599    if(creature->UpdateEntry(newEntryNum))
5600        SendSysMessage(LANG_DONE);
5601    else
5602        SendSysMessage(LANG_ERROR);
5603    return true;
5604}
5605
5606bool ChatHandler::HandleWritePDumpCommand(const char *args)
5607{
5608    if(!args)
5609        return false;
5610
5611    char* file = strtok((char*)args, " ");
5612    char* p2 = strtok(NULL, " ");
5613
5614    if(!file || !p2)
5615        return false;
5616
5617    uint32 guid = objmgr.GetPlayerGUIDByName(p2);
5618    if(!guid)
5619        guid = atoi(p2);
5620
5621    if(!objmgr.GetPlayerAccountIdByGUID(guid))
5622    {
5623        PSendSysMessage(LANG_PLAYER_NOT_FOUND);
5624        SetSentErrorMessage(true);
5625        return false;
5626    }
5627
5628    switch(PlayerDumpWriter().WriteDump(file, guid))
5629    {
5630        case DUMP_SUCCESS:
5631            PSendSysMessage(LANG_COMMAND_EXPORT_SUCCESS);
5632            break;
5633        case DUMP_FILE_OPEN_ERROR:
5634            PSendSysMessage(LANG_FILE_OPEN_FAIL,file);
5635            SetSentErrorMessage(true);
5636            return false;
5637        default:
5638            PSendSysMessage(LANG_COMMAND_EXPORT_FAILED);
5639            SetSentErrorMessage(true);
5640            return false;
5641    }
5642
5643    return true;
5644}
5645
5646bool ChatHandler::HandleMovegensCommand(const char* /*args*/)
5647{
5648    Unit* unit = getSelectedUnit();
5649    if(!unit)
5650    {
5651        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5652        SetSentErrorMessage(true);
5653        return false;
5654    }
5655
5656    PSendSysMessage(LANG_MOVEGENS_LIST,(unit->GetTypeId()==TYPEID_PLAYER ? "Player" : "Creature" ),unit->GetGUIDLow());
5657
5658    MotionMaster* mm = unit->GetMotionMaster();
5659    for(MotionMaster::const_iterator itr = mm->begin(); itr != mm->end(); ++itr)
5660    {
5661        switch((*itr)->GetMovementGeneratorType())
5662        {
5663            case IDLE_MOTION_TYPE:          SendSysMessage(LANG_MOVEGENS_IDLE);          break;
5664            case RANDOM_MOTION_TYPE:        SendSysMessage(LANG_MOVEGENS_RANDOM);        break;
5665            case WAYPOINT_MOTION_TYPE:      SendSysMessage(LANG_MOVEGENS_WAYPOINT);      break;
5666            case ANIMAL_RANDOM_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_ANIMAL_RANDOM); break;
5667            case CONFUSED_MOTION_TYPE:      SendSysMessage(LANG_MOVEGENS_CONFUSED);      break;
5668            case TARGETED_MOTION_TYPE:
5669            {
5670                if(unit->GetTypeId()==TYPEID_PLAYER)
5671                {
5672                    TargetedMovementGenerator<Player> const* mgen = static_cast<TargetedMovementGenerator<Player> const*>(*itr);
5673                    Unit* target = mgen->GetTarget();
5674                    if(target)
5675                        PSendSysMessage(LANG_MOVEGENS_TARGETED_PLAYER,target->GetName(),target->GetGUIDLow());
5676                    else
5677                        SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5678                }
5679                else
5680                {
5681                    TargetedMovementGenerator<Creature> const* mgen = static_cast<TargetedMovementGenerator<Creature> const*>(*itr);
5682                    Unit* target = mgen->GetTarget();
5683                    if(target)
5684                        PSendSysMessage(LANG_MOVEGENS_TARGETED_CREATURE,target->GetName(),target->GetGUIDLow());
5685                    else
5686                        SendSysMessage(LANG_MOVEGENS_TARGETED_NULL);
5687                }
5688                break;
5689            }
5690            case HOME_MOTION_TYPE:
5691                if(unit->GetTypeId()==TYPEID_UNIT)
5692                {
5693                    float x,y,z;
5694                    (*itr)->GetDestination(x,y,z);
5695                    PSendSysMessage(LANG_MOVEGENS_HOME_CREATURE,x,y,z);
5696                }
5697                else
5698                    SendSysMessage(LANG_MOVEGENS_HOME_PLAYER);
5699                break;
5700            case FLIGHT_MOTION_TYPE:   SendSysMessage(LANG_MOVEGENS_FLIGHT);  break;
5701            case POINT_MOTION_TYPE:
5702            {
5703                float x,y,z;
5704                (*itr)->GetDestination(x,y,z);
5705                PSendSysMessage(LANG_MOVEGENS_POINT,x,y,z);
5706                break;
5707            }
5708            case FLEEING_MOTION_TYPE:  SendSysMessage(LANG_MOVEGENS_FEAR);    break;
5709            case DISTRACT_MOTION_TYPE: SendSysMessage(LANG_MOVEGENS_DISTRACT);  break;
5710            default:
5711                PSendSysMessage(LANG_MOVEGENS_UNKNOWN,(*itr)->GetMovementGeneratorType());
5712                break;
5713        }
5714    }
5715    return true;
5716}
5717
5718bool ChatHandler::HandlePLimitCommand(const char *args)
5719{
5720    if(*args)
5721    {
5722        char* param = strtok((char*)args, " ");
5723        if(!param)
5724            return false;
5725
5726        int l = strlen(param);
5727
5728        if(     strncmp(param,"player",l) == 0 )
5729            sWorld.SetPlayerLimit(-SEC_PLAYER);
5730        else if(strncmp(param,"moderator",l) == 0 )
5731            sWorld.SetPlayerLimit(-SEC_MODERATOR);
5732        else if(strncmp(param,"gamemaster",l) == 0 )
5733            sWorld.SetPlayerLimit(-SEC_GAMEMASTER);
5734        else if(strncmp(param,"administrator",l) == 0 )
5735            sWorld.SetPlayerLimit(-SEC_ADMINISTRATOR);
5736        else if(strncmp(param,"reset",l) == 0 )
5737            sWorld.SetPlayerLimit( sConfig.GetIntDefault("PlayerLimit", DEFAULT_PLAYER_LIMIT) );
5738        else
5739        {
5740            int val = atoi(param);
5741            if(val < -SEC_ADMINISTRATOR) val = -SEC_ADMINISTRATOR;
5742
5743            sWorld.SetPlayerLimit(val);
5744        }
5745
5746        // kick all low security level players
5747        if(sWorld.GetPlayerAmountLimit() > SEC_PLAYER)
5748            sWorld.KickAllLess(sWorld.GetPlayerSecurityLimit());
5749    }
5750
5751    uint32 pLimit = sWorld.GetPlayerAmountLimit();
5752    AccountTypes allowedAccountType = sWorld.GetPlayerSecurityLimit();
5753    char const* secName = "";
5754    switch(allowedAccountType)
5755    {
5756        case SEC_PLAYER:        secName = "Player";        break;
5757        case SEC_MODERATOR:     secName = "Moderator";     break;
5758        case SEC_GAMEMASTER:    secName = "Gamemaster";    break;
5759        case SEC_ADMINISTRATOR: secName = "Administrator"; break;
5760        default:                secName = "<unknown>";     break;
5761    }
5762
5763    PSendSysMessage("Player limits: amount %u, min. security level %s.",pLimit,secName);
5764
5765    return true;
5766}
5767
5768bool ChatHandler::HandleCastCommand(const char* args)
5769{
5770    if(!*args)
5771        return false;
5772
5773    Unit* target = getSelectedUnit();
5774
5775    if(!target)
5776    {
5777        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5778        SetSentErrorMessage(true);
5779        return false;
5780    }
5781
5782    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5783    uint32 spell = extractSpellIdFromLink((char*)args);
5784    if(!spell)
5785        return false;
5786
5787    SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5788    if(!spellInfo)
5789        return false;
5790
5791    if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5792    {
5793        PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5794        SetSentErrorMessage(true);
5795        return false;
5796    }
5797
5798    char* trig_str = strtok(NULL, " ");
5799    if(trig_str)
5800    {
5801        int l = strlen(trig_str);
5802        if(strncmp(trig_str,"triggered",l) != 0 )
5803            return false;
5804    }
5805
5806    bool triggered = (trig_str != NULL);
5807
5808    m_session->GetPlayer()->CastSpell(target,spell,triggered);
5809
5810    return true;
5811}
5812
5813bool ChatHandler::HandleCastBackCommand(const char* args)
5814{
5815    Creature* caster = getSelectedCreature();
5816
5817    if(!caster)
5818    {
5819        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5820        SetSentErrorMessage(true);
5821        return false;
5822    }
5823
5824    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r
5825    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5826    uint32 spell = extractSpellIdFromLink((char*)args);
5827    if(!spell || !sSpellStore.LookupEntry(spell))
5828        return false;
5829
5830    char* trig_str = strtok(NULL, " ");
5831    if(trig_str)
5832    {
5833        int l = strlen(trig_str);
5834        if(strncmp(trig_str,"triggered",l) != 0 )
5835            return false;
5836    }
5837
5838    bool triggered = (trig_str != NULL);
5839
5840    // update orientation at server
5841    caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5842
5843    // and client
5844    WorldPacket data;
5845    caster->BuildHeartBeatMsg(&data);
5846    caster->SendMessageToSet(&data,true);
5847
5848    caster->CastSpell(m_session->GetPlayer(),spell,triggered);
5849
5850    return true;
5851}
5852
5853bool ChatHandler::HandleCastDistCommand(const char* args)
5854{
5855    if(!*args)
5856        return false;
5857
5858    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5859    uint32 spell = extractSpellIdFromLink((char*)args);
5860    if(!spell)
5861        return false;
5862
5863    SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5864    if(!spellInfo)
5865        return false;
5866
5867    if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5868    {
5869        PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
5870        SetSentErrorMessage(true);
5871        return false;
5872    }
5873
5874    char *distStr = strtok(NULL, " ");
5875
5876    float dist = 0;
5877
5878    if(distStr)
5879        sscanf(distStr, "%f", &dist);
5880
5881    char* trig_str = strtok(NULL, " ");
5882    if(trig_str)
5883    {
5884        int l = strlen(trig_str);
5885        if(strncmp(trig_str,"triggered",l) != 0 )
5886            return false;
5887    }
5888
5889    bool triggered = (trig_str != NULL);
5890
5891    float x,y,z;
5892    m_session->GetPlayer()->GetClosePoint(x,y,z,dist);
5893
5894    m_session->GetPlayer()->CastSpell(x,y,z,spell,triggered);
5895    return true;
5896}
5897
5898bool ChatHandler::HandleCastTargetCommand(const char* args)
5899{
5900    Creature* caster = getSelectedCreature();
5901
5902    if(!caster)
5903    {
5904        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5905        SetSentErrorMessage(true);
5906        return false;
5907    }
5908
5909    if(!caster->getVictim())
5910    {
5911        SendSysMessage(LANG_SELECTED_TARGET_NOT_HAVE_VICTIM);
5912        SetSentErrorMessage(true);
5913        return false;
5914    }
5915
5916    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5917    uint32 spell = extractSpellIdFromLink((char*)args);
5918    if(!spell || !sSpellStore.LookupEntry(spell))
5919        return false;
5920
5921    char* trig_str = strtok(NULL, " ");
5922    if(trig_str)
5923    {
5924        int l = strlen(trig_str);
5925        if(strncmp(trig_str,"triggered",l) != 0 )
5926            return false;
5927    }
5928
5929    bool triggered = (trig_str != NULL);
5930
5931    // update orientation at server
5932    caster->SetOrientation(caster->GetAngle(m_session->GetPlayer()));
5933
5934    // and client
5935    WorldPacket data;
5936    caster->BuildHeartBeatMsg(&data);
5937    caster->SendMessageToSet(&data,true);
5938
5939    caster->CastSpell(caster->getVictim(),spell,triggered);
5940
5941    return true;
5942}
5943
5944/*
5945ComeToMe command REQUIRED for 3rd party scripting library to have access to PointMovementGenerator
5946Without this function 3rd party scripting library will get linking errors (unresolved external)
5947when attempting to use the PointMovementGenerator
5948*/
5949bool ChatHandler::HandleComeToMeCommand(const char *args)
5950{
5951    Creature* caster = getSelectedCreature();
5952
5953    if(!caster)
5954    {
5955        SendSysMessage(LANG_SELECT_CREATURE);
5956        SetSentErrorMessage(true);
5957        return false;
5958    }
5959
5960    char* newFlagStr = strtok((char*)args, " ");
5961
5962    if(!newFlagStr)
5963        return false;
5964
5965    uint32 newFlags = atoi(newFlagStr);
5966
5967    caster->SetUnitMovementFlags(newFlags);
5968
5969    Player* pl = m_session->GetPlayer();
5970
5971    caster->GetMotionMaster()->MovePoint(0, pl->GetPositionX(), pl->GetPositionY(), pl->GetPositionZ());
5972    return true;
5973}
5974
5975bool ChatHandler::HandleCastSelfCommand(const char* args)
5976{
5977    if(!*args)
5978        return false;
5979
5980    Unit* target = getSelectedUnit();
5981
5982    if(!target)
5983    {
5984        SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
5985        SetSentErrorMessage(true);
5986        return false;
5987    }
5988
5989    // number or [name] Shift-click form |color|Hspell:spell_id|h[name]|h|r or Htalent form
5990    uint32 spell = extractSpellIdFromLink((char*)args);
5991    if(!spell)
5992        return false;
5993
5994    SpellEntry const* spellInfo = sSpellStore.LookupEntry(spell);
5995    if(!spellInfo)
5996        return false;
5997
5998    if(!SpellMgr::IsSpellValid(spellInfo,m_session->GetPlayer()))
5999    {
6000        PSendSysMessage(LANG_COMMAND_SPELL_BROKEN,spell);
6001        SetSentErrorMessage(true);
6002        return false;
6003    }
6004
6005    target->CastSpell(target,spell,false);
6006
6007    return true;
6008}
6009
6010std::string GetTimeString(uint32 time)
6011{
6012    uint16 days = time / DAY, hours = (time % DAY) / HOUR, minute = (time % HOUR) / MINUTE;
6013    std::ostringstream ss;
6014    if(days) ss << days << "d ";
6015    if(hours) ss << hours << "h ";
6016    ss << minute << "m";
6017    return ss.str();
6018}
6019
6020bool ChatHandler::HandleInstanceListBindsCommand(const char* /*args*/)
6021{
6022    Player* player = getSelectedPlayer();
6023    if (!player) player = m_session->GetPlayer();
6024    uint32 counter = 0;
6025    for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6026    {
6027        Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6028        for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6029        {
6030            InstanceSave *save = itr->second.save;
6031            std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6032            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());
6033            counter++;
6034        }
6035    }
6036    PSendSysMessage("player binds: %d", counter);
6037    counter = 0;
6038    Group *group = player->GetGroup();
6039    if(group)
6040    {
6041        for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6042        {
6043            Group::BoundInstancesMap &binds = group->GetBoundInstances(i);
6044            for(Group::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end(); ++itr)
6045            {
6046                InstanceSave *save = itr->second.save;
6047                std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6048                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());
6049                counter++;
6050            }
6051        }
6052    }
6053    PSendSysMessage("group binds: %d", counter);
6054
6055    return true;
6056}
6057
6058bool ChatHandler::HandleInstanceUnbindCommand(const char* args)
6059{
6060    if(!*args)
6061        return false;
6062
6063    std::string cmd = args;
6064    if(cmd == "all")
6065    {
6066        Player* player = getSelectedPlayer();
6067        if (!player) player = m_session->GetPlayer();
6068        uint32 counter = 0;
6069        for(uint8 i = 0; i < TOTAL_DIFFICULTIES; i++)
6070        {
6071            Player::BoundInstancesMap &binds = player->GetBoundInstances(i);
6072            for(Player::BoundInstancesMap::iterator itr = binds.begin(); itr != binds.end();)
6073            {
6074                if(itr->first != player->GetMapId())
6075                {
6076                    InstanceSave *save = itr->second.save;
6077                    std::string timeleft = GetTimeString(save->GetResetTime() - time(NULL));
6078                    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());
6079                    player->UnbindInstance(itr, i);
6080                    counter++;
6081                }
6082                else
6083                    ++itr;
6084            }
6085        }
6086        PSendSysMessage("instances unbound: %d", counter);
6087    }
6088    return true;
6089}
6090
6091bool ChatHandler::HandleInstanceStatsCommand(const char* /*args*/)
6092{
6093    PSendSysMessage("instances loaded: %d", MapManager::Instance().GetNumInstances());
6094    PSendSysMessage("players in instances: %d", MapManager::Instance().GetNumPlayersInInstances());
6095    PSendSysMessage("instance saves: %d", sInstanceSaveManager.GetNumInstanceSaves());
6096    PSendSysMessage("players bound: %d", sInstanceSaveManager.GetNumBoundPlayersTotal());
6097    PSendSysMessage("groups bound: %d", sInstanceSaveManager.GetNumBoundGroupsTotal());
6098    return true;
6099}
6100
6101bool ChatHandler::HandleInstanceSaveDataCommand(const char * /*args*/)
6102{
6103    Player* pl = m_session->GetPlayer();
6104
6105    Map* map = pl->GetMap();
6106    if (!map->IsDungeon())
6107    {
6108        PSendSysMessage("Map is not a dungeon.");
6109        SetSentErrorMessage(true);
6110        return false;
6111    }
6112
6113    if (!((InstanceMap*)map)->GetInstanceData())
6114    {
6115        PSendSysMessage("Map has no instance data.");
6116        SetSentErrorMessage(true);
6117        return false;
6118    }
6119
6120    ((InstanceMap*)map)->GetInstanceData()->SaveToDB();
6121    return true;
6122}
6123
6124/// Display the list of GMs
6125bool ChatHandler::HandleGMListFullCommand(const char* /*args*/)
6126{
6127    ///- Get the accounts with GM Level >0
6128    QueryResult *result = loginDatabase.Query( "SELECT username,gmlevel FROM account WHERE gmlevel > 0" );
6129    if(result)
6130    {
6131        SendSysMessage(LANG_GMLIST);
6132        SendSysMessage("========================");
6133        SendSysMessage(LANG_GMLIST_HEADER);
6134        SendSysMessage("========================");
6135
6136        ///- Circle through them. Display username and GM level
6137        do
6138        {
6139            Field *fields = result->Fetch();
6140            PSendSysMessage("|%15s|%6s|", fields[0].GetString(),fields[1].GetString());
6141        }while( result->NextRow() );
6142
6143        PSendSysMessage("========================");
6144        delete result;
6145    }
6146    else
6147        PSendSysMessage(LANG_GMLIST_EMPTY);
6148    return true;
6149}
6150
6151/// Define the 'Message of the day' for the realm
6152bool ChatHandler::HandleServerSetMotdCommand(const char* args)
6153{
6154    sWorld.SetMotd(args);
6155    PSendSysMessage(LANG_MOTD_NEW, args);
6156    return true;
6157}
6158
6159/// Set/Unset the expansion level for an account
6160bool ChatHandler::HandleAccountSetAddonCommand(const char* args)
6161{
6162    ///- Get the command line arguments
6163    char *szAcc = strtok((char*)args," ");
6164    char *szExp = strtok(NULL," ");
6165
6166    if(!szAcc)
6167        return false;
6168
6169    std::string account_name;
6170    uint32 account_id;
6171
6172    if(!szExp)
6173    {
6174        Player* player = getSelectedPlayer();
6175        if(!player)
6176            return false;
6177
6178        account_id = player->GetSession()->GetAccountId();
6179        accmgr.GetName(account_id,account_name);
6180        szExp = szAcc;
6181    }
6182    else
6183    {
6184        ///- Convert Account name to Upper Format
6185        account_name = szAcc;
6186        if(!AccountMgr::normilizeString(account_name))
6187        {
6188            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6189            SetSentErrorMessage(true);
6190            return false;
6191        }
6192
6193        account_id = accmgr.GetId(account_name);
6194        if(!account_id)
6195        {
6196            PSendSysMessage(LANG_ACCOUNT_NOT_EXIST,account_name.c_str());
6197            SetSentErrorMessage(true);
6198            return false;
6199        }
6200    }
6201
6202    int lev=atoi(szExp);                                    //get int anyway (0 if error)
6203    if(lev < 0)
6204        return false;
6205
6206    // No SQL injection
6207    loginDatabase.PExecute("UPDATE account SET expansion = '%d' WHERE id = '%u'",lev,account_id);
6208    PSendSysMessage(LANG_ACCOUNT_SETADDON,account_name.c_str(),account_id,lev);
6209    return true;
6210}
6211
6212/// Send a message to a player in game
6213bool ChatHandler::HandleSendMessageCommand(const char* args)
6214{
6215    ///- Get the command line arguments
6216    char* name_str = strtok((char*)args, " ");
6217    char* msg_str = strtok(NULL, "");
6218
6219    if(!name_str || !msg_str)
6220        return false;
6221
6222    std::string name = name_str;
6223
6224    if(!normalizePlayerName(name))
6225        return false;
6226
6227    ///- Find the player and check that he is not logging out.
6228    Player *rPlayer = objmgr.GetPlayer(name.c_str());
6229    if(!rPlayer)
6230    {
6231        SendSysMessage(LANG_PLAYER_NOT_FOUND);
6232        SetSentErrorMessage(true);
6233        return false;
6234    }
6235
6236    if(rPlayer->GetSession()->isLogingOut())
6237    {
6238        SendSysMessage(LANG_PLAYER_NOT_FOUND);
6239        SetSentErrorMessage(true);
6240        return false;
6241    }
6242
6243    ///- Send the message
6244    //Use SendAreaTriggerMessage for fastest delivery.
6245    rPlayer->GetSession()->SendAreaTriggerMessage("%s", msg_str);
6246    rPlayer->GetSession()->SendAreaTriggerMessage("|cffff0000[Message from administrator]:|r");
6247
6248    //Confirmation message
6249    PSendSysMessage(LANG_SENDMESSAGE,name.c_str(),msg_str);
6250    return true;
6251}
6252
6253bool ChatHandler::HandlePlayAllCommand(const char* args)
6254{
6255    if(!*args)
6256        return false;
6257
6258    uint32 soundId = atoi((char*)args);
6259
6260    if(!sSoundEntriesStore.LookupEntry(soundId))
6261    {
6262        PSendSysMessage(LANG_SOUND_NOT_EXIST, soundId);
6263        SetSentErrorMessage(true);
6264        return false;
6265    }
6266
6267    WorldPacket data(SMSG_PLAY_SOUND, 4);
6268    data << uint32(soundId) << m_session->GetPlayer()->GetGUID();
6269    sWorld.SendGlobalMessage(&data);
6270
6271    PSendSysMessage(LANG_COMMAND_PLAYED_TO_ALL, soundId);
6272    return true;
6273}
6274
6275bool ChatHandler::HandleModifyGenderCommand(const char *args)
6276{
6277    if(!*args)  return false;
6278    Player *player = getSelectedPlayer();
6279
6280    if(!player)
6281    {
6282        PSendSysMessage(LANG_NO_PLAYER);
6283        SetSentErrorMessage(true);
6284        return false;
6285    }
6286
6287    std::string gender = (char*)args;
6288    uint32 displayId = player->GetNativeDisplayId();
6289
6290    if(gender == "male") // MALE
6291    {
6292        if(player->getGender() == GENDER_MALE)
6293        {
6294            PSendSysMessage("%s is already male", player->GetName());
6295            SetSentErrorMessage(true);
6296            return false;
6297        }
6298
6299        // Set gender
6300        player->SetByteValue(UNIT_FIELD_BYTES_0, 2, GENDER_MALE);
6301        // Change display ID
6302        player->SetDisplayId(player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1);
6303        player->SetNativeDisplayId(player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1);
6304
6305        ChatHandler(player).PSendSysMessage("Gender changed. You are now a man!");
6306        PSendSysMessage("Gender changed for %s", player->GetName());
6307        return true;
6308    }
6309    else if(gender == "female") // FEMALE
6310    {
6311        if(player->getGender() == GENDER_FEMALE)
6312        {
6313            PSendSysMessage("%s is already female", player->GetName());
6314            SetSentErrorMessage(true);
6315            return false;
6316        }
6317
6318        // Set gender
6319        player->SetByteValue(UNIT_FIELD_BYTES_0, 2, GENDER_FEMALE);
6320        // Change display ID
6321        player->SetDisplayId(player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1);
6322        player->SetNativeDisplayId(player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1);
6323
6324        ChatHandler(player).PSendSysMessage("Gender changed. You are now a woman!");
6325        PSendSysMessage("Gender changed for %s", player->GetName());
6326        return true;
6327    }
6328    else
6329    {
6330        PSendSysMessage("You must use male or female as gender.");
6331        SetSentErrorMessage(true);
6332        return false;
6333    }
6334
6335    return true;
6336}
6337
6338bool ChatHandler::HandleFreezeCommand(const char *args)
6339{
6340    std::string name;
6341    Player* player;
6342    char* TargetName = strtok((char*)args, " "); //get entered name
6343    if (!TargetName) //if no name entered use target
6344    {
6345        player = getSelectedPlayer();
6346        if (player) //prevent crash with creature as target
6347        {   
6348            name = player->GetName();
6349            normalizePlayerName(name);
6350        }
6351    }
6352    else // if name entered
6353    {
6354        name = TargetName;
6355        normalizePlayerName(name);
6356        player = objmgr.GetPlayer(name.c_str()); //get player by name
6357    }
6358
6359    if (!player)
6360    {
6361        SendSysMessage(LANG_COMMAND_FREEZE_WRONG);
6362        return true;
6363    }
6364
6365    if (player==m_session->GetPlayer())
6366    {
6367        SendSysMessage(LANG_COMMAND_FREEZE_ERROR);
6368        return true;
6369    }
6370
6371    //effect
6372    if ((player) && (!(player==m_session->GetPlayer())))
6373    {
6374        PSendSysMessage(LANG_COMMAND_FREEZE,name.c_str());
6375
6376        //stop combat + make player unattackable + duel stop + stop some spells
6377        player->setFaction(35);
6378        player->CombatStop();
6379        if(player->IsNonMeleeSpellCasted(true))
6380            player->InterruptNonMeleeSpells(true);
6381        player->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
6382        player->SetUInt32Value(PLAYER_DUEL_TEAM, 1);
6383
6384        //if player class = hunter || warlock remove pet if alive
6385        if((player->getClass() == CLASS_HUNTER) || (player->getClass() == CLASS_WARLOCK))
6386        {
6387            if(Pet* pet = player->GetPet())
6388            {
6389                pet->SavePetToDB(PET_SAVE_AS_CURRENT);
6390                // not let dismiss dead pet
6391                if(pet && pet->isAlive())
6392                    player->RemovePet(pet,PET_SAVE_NOT_IN_SLOT);
6393            }
6394        }
6395
6396        //stop movement and disable spells
6397        uint32 spellID = 9454;
6398        //m_session->GetPlayer()->CastSpell(player,spellID,false);
6399        SpellEntry const *spellInfo = sSpellStore.LookupEntry( spellID );
6400        if(spellInfo) //TODO: Change the duration of the aura to -1 instead of 5000000
6401        {
6402            for(uint32 i = 0;i<3;i++)
6403            {
6404                uint8 eff = spellInfo->Effect[i];
6405                if (eff>=TOTAL_SPELL_EFFECTS)
6406                    continue;
6407                if( eff == SPELL_EFFECT_APPLY_AREA_AURA_PARTY || eff == SPELL_EFFECT_APPLY_AURA ||
6408                    eff == SPELL_EFFECT_PERSISTENT_AREA_AURA || eff == SPELL_EFFECT_APPLY_AREA_AURA_FRIEND || 
6409                    eff == SPELL_EFFECT_APPLY_AREA_AURA_ENEMY)
6410                {
6411                    Aura *Aur = CreateAura(spellInfo, i, NULL, player);
6412                    player->AddAura(Aur);
6413                }
6414            }
6415        }
6416
6417        //save player
6418        player->SaveToDB();
6419    }
6420    return true;
6421}
6422
6423bool ChatHandler::HandleUnFreezeCommand(const char *args)
6424{
6425    std::string name;
6426    Player* player;
6427    char* TargetName = strtok((char*)args, " "); //get entered name
6428    if (!TargetName) //if no name entered use target
6429    {
6430        player = getSelectedPlayer();
6431        if (player) //prevent crash with creature as target
6432        {   
6433            name = player->GetName();
6434        }
6435    }
6436
6437    else // if name entered
6438    {
6439        name = TargetName;
6440        normalizePlayerName(name);
6441        player = objmgr.GetPlayer(name.c_str()); //get player by name
6442    }
6443
6444    //effect
6445    if (player)
6446    {
6447        PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str());
6448
6449        //Reset player faction + allow combat + allow duels
6450        player->setFactionForRace(player->getRace());
6451        player->RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_NON_ATTACKABLE);
6452
6453        //allow movement and spells
6454        uint32 spellID = 9454;
6455        player->RemoveAurasDueToSpell(spellID);
6456
6457        //save player
6458        player->SaveToDB();
6459    }
6460
6461    if (!player)
6462    {
6463        if (TargetName)
6464        {       
6465            //check for offline players
6466            QueryResult *result = CharacterDatabase.PQuery("SELECT characters.guid FROM `characters` WHERE characters.name = '%s'",name.c_str());
6467            if(!result)
6468            {
6469                SendSysMessage(LANG_COMMAND_FREEZE_WRONG);
6470                return true;
6471            }
6472            //if player found: delete his freeze aura
6473            Field *fields=result->Fetch();
6474            uint64 pguid = fields[0].GetUInt64();
6475            delete result;
6476            CharacterDatabase.PQuery("DELETE FROM `character_aura` WHERE character_aura.spell = 9454 AND character_aura.guid = '%u'",pguid);
6477            PSendSysMessage(LANG_COMMAND_UNFREEZE,name.c_str());
6478            return true;
6479        }
6480        else
6481        {
6482            SendSysMessage(LANG_COMMAND_FREEZE_WRONG);
6483            return true;
6484        }
6485    }
6486
6487    return true;
6488}
6489
6490bool ChatHandler::HandleListFreezeCommand(const char* args)
6491{
6492    //Get names from DB
6493    QueryResult *result = CharacterDatabase.PQuery("SELECT characters.name FROM `characters` LEFT JOIN `character_aura` ON (characters.guid = character_aura.guid) WHERE character_aura.spell = 9454");
6494    if(!result)
6495    {
6496        SendSysMessage(LANG_COMMAND_NO_FROZEN_PLAYERS);
6497        return true;
6498    }
6499    //Header of the names
6500    PSendSysMessage(LANG_COMMAND_LIST_FREEZE);
6501
6502    //Output of the results
6503    do
6504    {
6505        Field *fields = result->Fetch();
6506        std::string fplayers = fields[0].GetCppString();
6507        PSendSysMessage(LANG_COMMAND_FROZEN_PLAYERS,fplayers.c_str());
6508    } while (result->NextRow());
6509
6510    delete result;
6511    return true;
6512}
6513
6514bool ChatHandler::HandleFlushArenaPointsCommand(const char * /*args*/)
6515{
6516    sBattleGroundMgr.DistributeArenaPoints();
6517    return true;
6518}
6519
6520bool ChatHandler::HandleGroupLeaderCommand(const char* args)
6521{
6522    Player* plr  = NULL;
6523    Group* group = NULL;
6524    uint64 guid  = 0;
6525    char* cname  = strtok((char*)args, " ");
6526
6527    if(GetPlayerGroupAndGUIDByName(cname, plr, group, guid))
6528        if(group && group->GetLeaderGUID() != guid)
6529            group->ChangeLeader(guid);
6530
6531    return true;
6532}
6533
6534bool ChatHandler::HandleGroupDisbandCommand(const char* args)
6535{
6536    Player* plr  = NULL;
6537    Group* group = NULL;
6538    uint64 guid  = 0;
6539    char* cname  = strtok((char*)args, " ");
6540
6541    if(GetPlayerGroupAndGUIDByName(cname, plr, group, guid))
6542        if(group)
6543            group->Disband();
6544
6545    return true;
6546}
6547
6548bool ChatHandler::HandleGroupRemoveCommand(const char* args)
6549{
6550    Player* plr  = NULL;
6551    Group* group = NULL;
6552    uint64 guid  = 0;
6553    char* cname  = strtok((char*)args, " ");
6554
6555    if(GetPlayerGroupAndGUIDByName(cname, plr, group, guid, true))
6556        if(group)
6557            group->RemoveMember(guid, 0);
6558
6559    return true;
6560}
6561
6562bool ChatHandler::HandlePossessCommand(const char* args)
6563{
6564    Unit* pUnit = getSelectedUnit();
6565    if(!pUnit)
6566        return false;
6567
6568    // Don't allow unlimited possession of players
6569    if (pUnit->GetTypeId() == TYPEID_PLAYER)
6570        return false;
6571
6572    m_session->GetPlayer()->Possess(pUnit);
6573
6574    return true;
6575}
6576
6577bool ChatHandler::HandleUnPossessCommand(const char* args)
6578{
6579    // Use this command to also unpossess ourselves
6580    if (m_session->GetPlayer()->isPossessed())
6581        m_session->GetPlayer()->UnpossessSelf(false);
6582    else
6583        m_session->GetPlayer()->RemovePossess(false);
6584
6585    return true;
6586}
Note: See TracBrowser for help on using the browser.