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

Revision 177, 176.6 kB (checked in by yumileroy, 17 years ago)

[svn] * Avoid access to bag item prototype for getting bag size, use related item
update field instead as more fast source. source mangos.
* Further reduce of DB access in guild handlers.
* Multi-locale DBC extracting - source Foks

*** Devs not responsible if all your player items drop to the ground and get eaten by ants or rabbits.. or some kind of wierd ant-rabbits..

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