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

Revision 112, 172.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Merge CLI Commands with regular commands and give them level4 access. sec_console. Source mangos - thanks to ogeraisi for the amalgamated patch.
* Redid/Fixed/Added some lang strings.
* As usual remember this is a trunk rev so stability only guaranteed on northern countries of Mars and western parts of Pluto. No warranties outside the solar system, sorry :( . Check with your local government or dictator on regulations regarding export.

Original author: KingPin?
Date: 2008-10-26 13:32:42-05:00

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