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

Revision 79, 157.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Minor code fixes
* Move account related functions from ObjectMgr? to AccountMgr? and drop duplicate functions - source mangos
* recognize the dummy spells 38637, 38638 and 38639 as negative - source mangos
* added new command ".reload all_locales". Now all locales_* tables can be reloaded - source mangos

Original author: KingPin?
Date: 2008-10-20 12:59:45-05:00

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