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

Revision 112, 65.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 "Player.h"
28#include "Opcodes.h"
29#include "Chat.h"
30#include "Log.h"
31#include "MapManager.h"
32#include "ObjectAccessor.h"
33#include "Language.h"
34#include "CellImpl.h"
35#include "InstanceSaveMgr.h"
36#include "Util.h"
37#ifdef _DEBUG_VMAPS
38#include "VMapFactory.h"
39#endif
40
41bool ChatHandler::HandleSayCommand(const char* args)
42{
43    if(!*args)
44        return false;
45
46    Creature* pCreature = getSelectedCreature();
47    if(!pCreature)
48    {
49        SendSysMessage(LANG_SELECT_CREATURE);
50        SetSentErrorMessage(true);
51        return false;
52    }
53
54    pCreature->Say(args, LANG_UNIVERSAL, 0);
55
56    return true;
57}
58
59bool ChatHandler::HandleYellCommand(const char* args)
60{
61    if(!*args)
62        return false;
63
64    Creature* pCreature = getSelectedCreature();
65    if(!pCreature)
66    {
67        SendSysMessage(LANG_SELECT_CREATURE);
68        SetSentErrorMessage(true);
69        return false;
70    }
71
72    pCreature->Yell(args, LANG_UNIVERSAL, 0);
73
74    return true;
75}
76
77//show text emote by creature in chat
78bool ChatHandler::HandleTextEmoteCommand(const char* args)
79{
80    if(!*args)
81        return false;
82
83    Creature* pCreature = getSelectedCreature();
84
85    if(!pCreature)
86    {
87        SendSysMessage(LANG_SELECT_CREATURE);
88        SetSentErrorMessage(true);
89        return false;
90    }
91
92    pCreature->TextEmote(args, 0);
93
94    return true;
95}
96
97// make npc whisper to player
98bool ChatHandler::HandleNpcWhisperCommand(const char* args)
99{
100    if(!*args)
101        return false;
102
103    char* receiver_str = strtok((char*)args, " ");
104    char* text = strtok(NULL, "");
105
106    uint64 guid = m_session->GetPlayer()->GetSelection();
107    Creature* pCreature = ObjectAccessor::GetCreature(*m_session->GetPlayer(), guid);
108
109    if(!pCreature || !receiver_str || !text)
110    {
111        return false;
112    }
113
114    uint64 receiver_guid= atol(receiver_str);
115
116    pCreature->Whisper(text,receiver_guid);
117
118    return true;
119}
120
121bool ChatHandler::HandleNameAnnounceCommand(const char* args)
122{
123    WorldPacket data;
124    if(!*args)
125        return false;
126    //char str[1024];
127    //sprintf(str, GetTrinityString(LANG_ANNOUNCE_COLOR), m_session->GetPlayer()->GetName(), args);
128    sWorld.SendWorldText(LANG_ANNOUNCE_COLOR, m_session->GetPlayer()->GetName(), args);
129    return true;
130}
131
132// global announce
133bool ChatHandler::HandleAnnounceCommand(const char* args)
134{
135    if(!*args)
136        return false;
137
138    sWorld.SendWorldText(LANG_SYSTEMMESSAGE,args);
139
140    return true;
141}
142
143//notification player at the screen
144bool ChatHandler::HandleNotifyCommand(const char* args)
145{
146    if(!*args)
147        return false;
148
149    std::string str = GetTrinityString(LANG_GLOBAL_NOTIFY);
150    str += args;
151
152    WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
153    data << str;
154    sWorld.SendGlobalMessage(&data);
155
156    return true;
157}
158
159//Enable\Dissable GM Mode
160bool ChatHandler::HandleGMmodeCommand(const char* args)
161{
162    if(!*args)
163    {
164        if(m_session->GetPlayer()->isGameMaster())
165            m_session->SendNotification(LANG_GM_ON);
166        else
167            m_session->SendNotification(LANG_GM_OFF);
168        return true;
169    }
170
171    std::string argstr = (char*)args;
172
173    if (argstr == "on")
174    {
175        m_session->GetPlayer()->SetGameMaster(true);
176        m_session->SendNotification(LANG_GM_ON);
177        #ifdef _DEBUG_VMAPS
178        VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
179        vMapManager->processCommand("stoplog");
180        #endif
181        return true;
182    }
183
184    if (argstr == "off")
185    {
186        m_session->GetPlayer()->SetGameMaster(false);
187        m_session->SendNotification(LANG_GM_OFF);
188        #ifdef _DEBUG_VMAPS
189        VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
190        vMapManager->processCommand("startlog");
191        #endif
192        return true;
193    }
194
195    SendSysMessage(LANG_USE_BOL);
196    SetSentErrorMessage(true);
197    return false;
198}
199
200// Enables or disables hiding of the staff badge
201bool ChatHandler::HandleGMChatCommand(const char* args)
202{
203    if(!*args)
204    {
205        if(m_session->GetPlayer()->isGMChat())
206            m_session->SendNotification(LANG_GM_CHAT_ON);
207        else
208            m_session->SendNotification(LANG_GM_CHAT_OFF);
209        return true;
210    }
211
212    std::string argstr = (char*)args;
213
214    if (argstr == "on")
215    {
216        m_session->GetPlayer()->SetGMChat(true);
217        m_session->SendNotification(LANG_GM_CHAT_ON);
218        return true;
219    }
220
221    if (argstr == "off")
222    {
223        m_session->GetPlayer()->SetGMChat(false);
224        m_session->SendNotification(LANG_GM_CHAT_OFF);
225        return true;
226    }
227
228    SendSysMessage(LANG_USE_BOL);
229    SetSentErrorMessage(true);
230    return false;
231}
232
233
234//Enable\Dissable Invisible mode
235bool ChatHandler::HandleVisibleCommand(const char* args)
236{
237    if (!*args)
238    {
239        PSendSysMessage(LANG_YOU_ARE, m_session->GetPlayer()->isGMVisible() ?  GetTrinityString(LANG_VISIBLE) : GetTrinityString(LANG_INVISIBLE));
240        return true;
241    }
242
243    std::string argstr = (char*)args;
244
245    if (argstr == "on")
246    {
247        m_session->GetPlayer()->SetGMVisible(true);
248        m_session->SendNotification(LANG_INVISIBLE_VISIBLE);
249        return true;
250    }
251
252    if (argstr == "off")
253    {
254        m_session->SendNotification(LANG_INVISIBLE_INVISIBLE);
255        m_session->GetPlayer()->SetGMVisible(false);
256        return true;
257    }
258
259    SendSysMessage(LANG_USE_BOL);
260    SetSentErrorMessage(true);
261    return false;
262}
263
264bool ChatHandler::HandleGPSCommand(const char* args)
265{
266    WorldObject *obj = NULL;
267    if (*args)
268    {
269        std::string name = args;
270        if(normalizePlayerName(name))
271            obj = objmgr.GetPlayer(name.c_str());
272
273        if(!obj)
274        {
275            SendSysMessage(LANG_PLAYER_NOT_FOUND);
276            SetSentErrorMessage(true);
277            return false;
278        }
279    }
280    else
281    {
282        obj = getSelectedUnit();
283
284        if(!obj)
285        {
286            SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
287            SetSentErrorMessage(true);
288            return false;
289        }
290    }
291    CellPair cell_val = Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
292    Cell cell(cell_val);
293
294    uint32 zone_id = obj->GetZoneId();
295    uint32 area_id = obj->GetAreaId();
296
297    MapEntry const* mapEntry = sMapStore.LookupEntry(obj->GetMapId());
298    AreaTableEntry const* zoneEntry = GetAreaEntryByAreaID(zone_id);
299    AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(area_id);
300
301    float zone_x = obj->GetPositionX();
302    float zone_y = obj->GetPositionY();
303
304    Map2ZoneCoordinates(zone_x,zone_y,zone_id);
305
306    Map const *map = MapManager::Instance().GetMap(obj->GetMapId(), obj);
307    float ground_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), MAX_HEIGHT);
308    float floor_z = map->GetHeight(obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ());
309
310    GridPair p = Trinity::ComputeGridPair(obj->GetPositionX(), obj->GetPositionY());
311
312    int gx=63-p.x_coord;
313    int gy=63-p.y_coord;
314
315    uint32 have_map = Map::ExistMap(obj->GetMapId(),gx,gy) ? 1 : 0;
316    uint32 have_vmap = Map::ExistVMap(obj->GetMapId(),gx,gy) ? 1 : 0;
317
318    PSendSysMessage(LANG_MAP_POSITION,
319        obj->GetMapId(), (mapEntry ? mapEntry->name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
320        zone_id, (zoneEntry ? zoneEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
321        area_id, (areaEntry ? areaEntry->area_name[m_session->GetSessionDbcLocale()] : "<unknown>" ),
322        obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
323        cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
324        zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
325
326    sLog.outDebug("Player %s GPS call for %s '%s' (%s: %u):",
327        m_session->GetPlayer()->GetName(),
328        (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetName(),
329        (obj->GetTypeId() == TYPEID_PLAYER ? "GUID" : "Entry"), (obj->GetTypeId() == TYPEID_PLAYER ? obj->GetGUIDLow(): obj->GetEntry()) );
330    sLog.outDebug(GetTrinityString(LANG_MAP_POSITION),
331        obj->GetMapId(), (mapEntry ? mapEntry->name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
332        zone_id, (zoneEntry ? zoneEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
333        area_id, (areaEntry ? areaEntry->area_name[sWorld.GetDefaultDbcLocale()] : "<unknown>" ),
334        obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(), obj->GetOrientation(),
335        cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY(), obj->GetInstanceId(),
336        zone_x, zone_y, ground_z, floor_z, have_map, have_vmap );
337
338    return true;
339}
340
341//Summon Player
342bool ChatHandler::HandleNamegoCommand(const char* args)
343{
344    if(!*args)
345        return false;
346
347    std::string name = args;
348
349    if(!normalizePlayerName(name))
350    {
351        SendSysMessage(LANG_PLAYER_NOT_FOUND);
352        SetSentErrorMessage(true);
353        return false;
354    }
355
356    Player *chr = objmgr.GetPlayer(name.c_str());
357    if (chr)
358    {
359        if(chr->IsBeingTeleported()==true)
360        {
361            PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
362            SetSentErrorMessage(true);
363            return false;
364        }
365
366        Map* pMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
367
368        if(pMap->IsBattleGroundOrArena())
369        {
370            // cannot summon to bg
371            SendSysMessage(LANG_CANNOT_SUMMON_TO_BG);
372            SetSentErrorMessage(true);
373            return false;
374        }
375        else if(pMap->IsDungeon())
376        {
377            Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
378            if( cMap->Instanceable() && cMap->GetInstanceId() != pMap->GetInstanceId() )
379            {
380                // cannot summon from instance to instance
381                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
382                SetSentErrorMessage(true);
383                return false;
384            }
385
386            // we are in instance, and can summon only player in our group with us as lead
387            if ( !m_session->GetPlayer()->GetGroup() || !chr->GetGroup() ||
388                (chr->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
389                (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
390                // the last check is a bit excessive, but let it be, just in case
391            {
392                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
393                SetSentErrorMessage(true);
394                return false;
395            }
396        }
397
398        PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
399
400        if (m_session->GetPlayer()->IsVisibleGloballyFor(chr))
401            ChatHandler(chr).PSendSysMessage(LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
402
403        // stop flight if need
404        if(chr->isInFlight())
405        {
406            chr->GetMotionMaster()->MovementExpired();
407            chr->m_taxi.ClearTaxiDestinations();
408        }
409        // save only in non-flight case
410        else
411            chr->SaveRecallPosition();
412
413        // before GM
414        float x,y,z;
415        m_session->GetPlayer()->GetClosePoint(x,y,z,chr->GetObjectSize());
416        chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
417    }
418    else if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
419    {
420        PSendSysMessage(LANG_SUMMONING, name.c_str(),GetTrinityString(LANG_OFFLINE));
421
422        // in point where GM stay
423        Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
424            m_session->GetPlayer()->GetPositionX(),
425            m_session->GetPlayer()->GetPositionY(),
426            m_session->GetPlayer()->GetPositionZ(),
427            m_session->GetPlayer()->GetOrientation(),
428            m_session->GetPlayer()->GetZoneId(),
429            guid);
430    }
431    else
432    {
433        PSendSysMessage(LANG_NO_PLAYER, args);
434        SetSentErrorMessage(true);
435    }
436
437    return true;
438}
439
440//Teleport to Player
441bool ChatHandler::HandleGonameCommand(const char* args)
442{
443    if(!*args)
444        return false;
445
446    Player* _player = m_session->GetPlayer();
447
448    std::string name = args;
449
450    if(!normalizePlayerName(name))
451    {
452        SendSysMessage(LANG_PLAYER_NOT_FOUND);
453        SetSentErrorMessage(true);
454        return false;
455    }
456
457    Player *chr = objmgr.GetPlayer(name.c_str());
458    if (chr)
459    {
460        Map* cMap = MapManager::Instance().GetMap(chr->GetMapId(),chr);
461        if(cMap->IsBattleGroundOrArena())
462        {
463            // only allow if gm mode is on
464            if (!_player->isGameMaster())
465            {
466                SendSysMessage(LANG_CANNOT_GO_TO_BG_GM);
467                SetSentErrorMessage(true);
468                return false;
469            }
470            // if already in a bg, don't let port to other
471            else if (_player->GetBattleGroundId())
472            {
473                SendSysMessage(LANG_CANNOT_GO_TO_BG_FROM_BG);
474                SetSentErrorMessage(true);
475                return false;
476            }
477            // all's well, set bg id
478            // when porting out from the bg, it will be reset to 0
479            _player->SetBattleGroundId(chr->GetBattleGroundId());
480        }
481        else if(cMap->IsDungeon())
482        {
483            Map* pMap = MapManager::Instance().GetMap(_player->GetMapId(),_player);
484
485            // we have to go to instance, and can go to player only if:
486            //   1) we are in his group (either as leader or as member)
487            //   2) we are not bound to any group and have GM mode on
488            if (_player->GetGroup())
489            {
490                // we are in group, we can go only if we are in the player group
491                if (_player->GetGroup() != chr->GetGroup())
492                {
493                    PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName());
494                    SetSentErrorMessage(true);
495                    return false;
496                }
497            }
498            else
499            {
500                // we are not in group, let's verify our GM mode
501                if (!_player->isGameMaster())
502                {
503                    PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName());
504                    SetSentErrorMessage(true);
505                    return false;
506                }
507            }
508
509            // if the player or the player's group is bound to another instance
510            // the player will not be bound to another one
511            InstancePlayerBind *pBind = _player->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty());
512            if(!pBind)
513            {
514                Group *group = _player->GetGroup();
515                InstanceGroupBind *gBind = group ? group->GetBoundInstance(chr->GetMapId(), chr->GetDifficulty()) : NULL;
516                if(!gBind)
517                {
518                    // if no bind exists, create a solo bind
519                    InstanceSave *save = sInstanceSaveManager.GetInstanceSave(chr->GetInstanceId());
520                    if(save) _player->BindToInstance(save, !save->CanReset());
521                }
522            }
523
524            _player->SetDifficulty(chr->GetDifficulty());
525        }
526
527        PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
528
529        if (_player->IsVisibleGloballyFor(chr))
530            ChatHandler(chr).PSendSysMessage(LANG_APPEARING_TO, _player->GetName());
531
532        // stop flight if need
533        if(_player->isInFlight())
534        {
535            _player->GetMotionMaster()->MovementExpired();
536            _player->m_taxi.ClearTaxiDestinations();
537        }
538        // save only in non-flight case
539        else
540            _player->SaveRecallPosition();
541
542        // to point to see at target with same orientation
543        float x,y,z;
544        chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
545
546        _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), TELE_TO_GM_MODE);
547
548        return true;
549    }
550
551    if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
552    {
553        PSendSysMessage(LANG_APPEARING_AT, name.c_str());
554
555        // to point where player stay (if loaded)
556        float x,y,z,o;
557        uint32 map;
558        bool in_flight;
559        if(Player::LoadPositionFromDB(map,x,y,z,o,in_flight,guid))
560        {
561            // stop flight if need
562            if(_player->isInFlight())
563            {
564                _player->GetMotionMaster()->MovementExpired();
565                _player->m_taxi.ClearTaxiDestinations();
566            }
567            // save only in non-flight case
568            else
569                _player->SaveRecallPosition();
570
571            _player->TeleportTo(map, x, y, z,_player->GetOrientation());
572            return true;
573        }
574    }
575
576    PSendSysMessage(LANG_NO_PLAYER, args);
577
578    SetSentErrorMessage(true);
579    return false;
580}
581
582// Teleport player to last position
583bool ChatHandler::HandleRecallCommand(const char* args)
584{
585    Player* chr = NULL;
586
587    if(!*args)
588    {
589        chr = getSelectedPlayer();
590        if(!chr)
591            chr = m_session->GetPlayer();
592    }
593    else
594    {
595        std::string name = args;
596
597        if(!normalizePlayerName(name))
598        {
599            SendSysMessage(LANG_PLAYER_NOT_FOUND);
600            SetSentErrorMessage(true);
601            return false;
602        }
603
604        chr = objmgr.GetPlayer(name.c_str());
605
606        if(!chr)
607        {
608            PSendSysMessage(LANG_NO_PLAYER, args);
609            SetSentErrorMessage(true);
610            return false;
611        }
612    }
613
614    if(chr->IsBeingTeleported())
615    {
616        PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
617        SetSentErrorMessage(true);
618        return false;
619    }
620
621    // stop flight if need
622    if(chr->isInFlight())
623    {
624        chr->GetMotionMaster()->MovementExpired();
625        chr->m_taxi.ClearTaxiDestinations();
626    }
627
628    chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
629    return true;
630}
631
632//Edit Player KnownTitles
633bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
634{
635    if(!*args)
636        return false;
637
638    uint64 titles = 0;
639
640    sscanf((char*)args, I64FMTD, &titles);
641
642    Player *chr = getSelectedPlayer();
643    if (!chr)
644    {
645        SendSysMessage(LANG_NO_CHAR_SELECTED);
646        SetSentErrorMessage(true);
647        return false;
648    }
649
650    uint64 titles2 = titles;
651
652    for(int i=1; i < sCharTitlesStore.GetNumRows(); ++i)
653        if(CharTitlesEntry const* tEntry = sCharTitlesStore.LookupEntry(i))
654            titles2 &= ~(uint64(1) << tEntry->bit_index);
655
656    titles &= ~titles2;                                     // remove not existed titles
657
658    chr->SetUInt64Value(PLAYER__FIELD_KNOWN_TITLES, titles);
659    SendSysMessage(LANG_DONE);
660
661    return true;
662}
663
664//Edit Player HP
665bool ChatHandler::HandleModifyHPCommand(const char* args)
666{
667    if(!*args)
668        return false;
669
670    //    char* pHp = strtok((char*)args, " ");
671    //    if (!pHp)
672    //        return false;
673
674    //    char* pHpMax = strtok(NULL, " ");
675    //    if (!pHpMax)
676    //        return false;
677
678    //    int32 hpm = atoi(pHpMax);
679    //    int32 hp = atoi(pHp);
680
681    int32 hp = atoi((char*)args);
682    int32 hpm = atoi((char*)args);
683
684    if (hp <= 0 || hpm <= 0 || hpm < hp)
685    {
686        SendSysMessage(LANG_BAD_VALUE);
687        SetSentErrorMessage(true);
688        return false;
689    }
690
691    Player *chr = getSelectedPlayer();
692    if (chr == NULL)
693    {
694        SendSysMessage(LANG_NO_CHAR_SELECTED);
695        SetSentErrorMessage(true);
696        return false;
697    }
698
699    PSendSysMessage(LANG_YOU_CHANGE_HP, chr->GetName(), hp, hpm);
700    ChatHandler(chr).PSendSysMessage(LANG_YOURS_HP_CHANGED, m_session->GetPlayer()->GetName(), hp, hpm);
701
702    chr->SetMaxHealth( hpm );
703    chr->SetHealth( hp );
704
705    return true;
706}
707
708//Edit Player Mana
709bool ChatHandler::HandleModifyManaCommand(const char* args)
710{
711    if(!*args)
712        return false;
713
714    // char* pmana = strtok((char*)args, " ");
715    // if (!pmana)
716    //     return false;
717
718    // char* pmanaMax = strtok(NULL, " ");
719    // if (!pmanaMax)
720    //     return false;
721
722    // int32 manam = atoi(pmanaMax);
723    // int32 mana = atoi(pmana);
724    int32 mana = atoi((char*)args);
725    int32 manam = atoi((char*)args);
726
727    if (mana <= 0 || manam <= 0 || manam < mana)
728    {
729        SendSysMessage(LANG_BAD_VALUE);
730        SetSentErrorMessage(true);
731        return false;
732    }
733
734    Player *chr = getSelectedPlayer();
735    if (chr == NULL)
736    {
737        SendSysMessage(LANG_NO_CHAR_SELECTED);
738        SetSentErrorMessage(true);
739        return false;
740    }
741
742    PSendSysMessage(LANG_YOU_CHANGE_MANA, chr->GetName(), mana, manam);
743    ChatHandler(chr).PSendSysMessage(LANG_YOURS_MANA_CHANGED, m_session->GetPlayer()->GetName(), mana, manam);
744
745    chr->SetMaxPower(POWER_MANA,manam );
746    chr->SetPower(POWER_MANA, mana );
747
748    return true;
749}
750
751//Edit Player Energy
752bool ChatHandler::HandleModifyEnergyCommand(const char* args)
753{
754    if(!*args)
755        return false;
756
757    // char* pmana = strtok((char*)args, " ");
758    // if (!pmana)
759    //     return false;
760
761    // char* pmanaMax = strtok(NULL, " ");
762    // if (!pmanaMax)
763    //     return false;
764
765    // int32 manam = atoi(pmanaMax);
766    // int32 mana = atoi(pmana);
767
768    int32 energy = atoi((char*)args)*10;
769    int32 energym = atoi((char*)args)*10;
770
771    if (energy <= 0 || energym <= 0 || energym < energy)
772    {
773        SendSysMessage(LANG_BAD_VALUE);
774        SetSentErrorMessage(true);
775        return false;
776    }
777
778    Player *chr = getSelectedPlayer();
779    if (!chr)
780    {
781        SendSysMessage(LANG_NO_CHAR_SELECTED);
782        SetSentErrorMessage(true);
783        return false;
784    }
785
786    PSendSysMessage(LANG_YOU_CHANGE_ENERGY, chr->GetName(), energy/10, energym/10);
787    ChatHandler(chr).PSendSysMessage(LANG_YOURS_ENERGY_CHANGED, m_session->GetPlayer()->GetName(), energy/10, energym/10);
788
789    chr->SetMaxPower(POWER_ENERGY,energym );
790    chr->SetPower(POWER_ENERGY, energy );
791
792    sLog.outDetail(GetTrinityString(LANG_CURRENT_ENERGY),chr->GetMaxPower(POWER_ENERGY));
793
794    return true;
795}
796
797//Edit Player Rage
798bool ChatHandler::HandleModifyRageCommand(const char* args)
799{
800    if(!*args)
801        return false;
802
803    // char* pmana = strtok((char*)args, " ");
804    // if (!pmana)
805    //     return false;
806
807    // char* pmanaMax = strtok(NULL, " ");
808    // if (!pmanaMax)
809    //     return false;
810
811    // int32 manam = atoi(pmanaMax);
812    // int32 mana = atoi(pmana);
813
814    int32 rage = atoi((char*)args)*10;
815    int32 ragem = atoi((char*)args)*10;
816
817    if (rage <= 0 || ragem <= 0 || ragem < rage)
818    {
819        SendSysMessage(LANG_BAD_VALUE);
820        SetSentErrorMessage(true);
821        return false;
822    }
823
824    Player *chr = getSelectedPlayer();
825    if (chr == NULL)
826    {
827        SendSysMessage(LANG_NO_CHAR_SELECTED);
828        SetSentErrorMessage(true);
829        return false;
830    }
831
832    PSendSysMessage(LANG_YOU_CHANGE_RAGE, chr->GetName(), rage/10, ragem/10);
833    ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_RAGE_CHANGED), m_session->GetPlayer()->GetName(), rage/10, ragem/10);
834
835    chr->SetMaxPower(POWER_RAGE,ragem );
836    chr->SetPower(POWER_RAGE, rage );
837
838    return true;
839}
840
841//Edit Player Faction
842bool ChatHandler::HandleModifyFactionCommand(const char* args)
843{
844    if(!*args)
845        return false;
846
847    char* pfactionid = extractKeyFromLink((char*)args,"Hfaction");
848
849    Creature* chr = getSelectedCreature();
850    if(!chr)
851    {
852        SendSysMessage(LANG_SELECT_CREATURE);
853        SetSentErrorMessage(true);
854        return false;
855    }
856
857    if(!pfactionid)
858    {
859        if(chr)
860        {
861            uint32 factionid = chr->getFaction();
862            uint32 flag      = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
863            uint32 npcflag   = chr->GetUInt32Value(UNIT_NPC_FLAGS);
864            uint32 dyflag    = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
865            PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
866        }
867        return true;
868    }
869
870    if( !chr )
871    {
872        SendSysMessage(LANG_NO_CHAR_SELECTED);
873        SetSentErrorMessage(true);
874        return false;
875    }
876
877    uint32 factionid = atoi(pfactionid);
878    uint32 flag;
879
880    char *pflag = strtok(NULL, " ");
881    if (!pflag)
882        flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
883    else
884        flag = atoi(pflag);
885
886    char* pnpcflag = strtok(NULL, " ");
887
888    uint32 npcflag;
889    if(!pnpcflag)
890        npcflag   = chr->GetUInt32Value(UNIT_NPC_FLAGS);
891    else
892        npcflag = atoi(pnpcflag);
893
894    char* pdyflag = strtok(NULL, " ");
895
896    uint32  dyflag;
897    if(!pdyflag)
898        dyflag   = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
899    else
900        dyflag = atoi(pdyflag);
901
902    if(!sFactionTemplateStore.LookupEntry(factionid))
903    {
904        PSendSysMessage(LANG_WRONG_FACTION, factionid);
905        SetSentErrorMessage(true);
906        return false;
907    }
908
909    PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
910
911    //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
912    //FillSystemMessageData(&data, m_session, buf);
913
914    //chr->GetSession()->SendPacket(&data);
915
916    chr->setFaction(factionid);
917    chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
918    chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
919    chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
920
921    return true;
922}
923
924//Edit Player Spell
925bool ChatHandler::HandleModifySpellCommand(const char* args)
926{
927    if(!*args) return false;
928    char* pspellflatid = strtok((char*)args, " ");
929    if (!pspellflatid)
930        return false;
931
932    char* pop = strtok(NULL, " ");
933    if (!pop)
934        return false;
935
936    char* pval = strtok(NULL, " ");
937    if (!pval)
938        return false;
939
940    uint16 mark;
941
942    char* pmark = strtok(NULL, " ");
943
944    uint8 spellflatid = atoi(pspellflatid);
945    uint8 op   = atoi(pop);
946    uint16 val = atoi(pval);
947    if(!pmark)
948        mark = 65535;
949    else
950        mark = atoi(pmark);
951
952    Player *chr = getSelectedPlayer();
953    if (chr == NULL)
954    {
955        SendSysMessage(LANG_NO_CHAR_SELECTED);
956        SetSentErrorMessage(true);
957        return false;
958    }
959
960    PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
961    if(chr != m_session->GetPlayer())
962        ChatHandler(chr).PSendSysMessage(LANG_YOURS_SPELLFLATID_CHANGED, m_session->GetPlayer()->GetName(), spellflatid, val, mark);
963
964    WorldPacket data(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
965    data << uint8(spellflatid);
966    data << uint8(op);
967    data << uint16(val);
968    data << uint16(mark);
969    chr->GetSession()->SendPacket(&data);
970
971    return true;
972}
973
974//Edit Player TP
975bool ChatHandler::HandleModifyTalentCommand (const char* args)
976{
977    if (!*args)
978        return false;
979
980    int tp = atoi((char*)args);
981    if (tp>0)
982    {
983        Player* player = getSelectedPlayer();
984        if(!player)
985        {
986            SendSysMessage(LANG_NO_CHAR_SELECTED);
987            SetSentErrorMessage(true);
988            return false;
989        }
990        player->SetFreeTalentPoints(tp);
991        return true;
992    }
993    return false;
994}
995
996//Enable On\OFF all taxi paths
997bool ChatHandler::HandleTaxiCheatCommand(const char* args)
998{
999    if (!*args)
1000    {
1001        SendSysMessage(LANG_USE_BOL);
1002        SetSentErrorMessage(true);
1003        return false;
1004    }
1005
1006    std::string argstr = (char*)args;
1007
1008    Player *chr = getSelectedPlayer();
1009    if (!chr)
1010    {
1011        chr=m_session->GetPlayer();
1012    }
1013
1014    if (argstr == "on")
1015    {
1016        chr->SetTaxiCheater(true);
1017        PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
1018
1019        if(chr != m_session->GetPlayer())
1020            // to send localized data to target
1021            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_TAXIS_ADDED), m_session->GetPlayer()->GetName());
1022        return true;
1023    }
1024
1025    if (argstr == "off")
1026    {
1027        chr->SetTaxiCheater(false);
1028        PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
1029
1030        if(chr != m_session->GetPlayer())
1031            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_TAXIS_REMOVED), m_session->GetPlayer()->GetName());
1032
1033        return true;
1034    }
1035
1036    SendSysMessage(LANG_USE_BOL);
1037    SetSentErrorMessage(true);
1038    return false;
1039}
1040
1041//Edit Player Aspeed
1042bool ChatHandler::HandleModifyASpeedCommand(const char* args)
1043{
1044    if (!*args)
1045        return false;
1046
1047    float ASpeed = (float)atof((char*)args);
1048
1049    if (ASpeed > 10 || ASpeed < 0.1)
1050    {
1051        SendSysMessage(LANG_BAD_VALUE);
1052        SetSentErrorMessage(true);
1053        return false;
1054    }
1055
1056    Player *chr = getSelectedPlayer();
1057    if (chr == NULL)
1058    {
1059        SendSysMessage(LANG_NO_CHAR_SELECTED);
1060        SetSentErrorMessage(true);
1061        return false;
1062    }
1063
1064    if(chr->isInFlight())
1065    {
1066        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1067        SetSentErrorMessage(true);
1068        return false;
1069    }
1070
1071    PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
1072
1073    if(chr != m_session->GetPlayer())
1074        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_ASPEED_CHANGED), m_session->GetPlayer()->GetName(), ASpeed);
1075
1076    chr->SetSpeed(MOVE_WALK,    ASpeed,true);
1077    chr->SetSpeed(MOVE_RUN,     ASpeed,true);
1078    chr->SetSpeed(MOVE_SWIM,    ASpeed,true);
1079    //chr->SetSpeed(MOVE_TURN,    ASpeed,true);
1080    chr->SetSpeed(MOVE_FLY,     ASpeed,true);
1081    return true;
1082}
1083
1084//Edit Player Speed
1085bool ChatHandler::HandleModifySpeedCommand(const char* args)
1086{
1087    if (!*args)
1088        return false;
1089
1090    float Speed = (float)atof((char*)args);
1091
1092    if (Speed > 10 || Speed < 0.1)
1093    {
1094        SendSysMessage(LANG_BAD_VALUE);
1095        SetSentErrorMessage(true);
1096        return false;
1097    }
1098
1099    Player *chr = getSelectedPlayer();
1100    if (chr == NULL)
1101    {
1102        SendSysMessage(LANG_NO_CHAR_SELECTED);
1103        SetSentErrorMessage(true);
1104        return false;
1105    }
1106
1107    if(chr->isInFlight())
1108    {
1109        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1110        SetSentErrorMessage(true);
1111        return false;
1112    }
1113
1114    PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
1115
1116    if(chr != m_session->GetPlayer())
1117        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_SPEED_CHANGED), m_session->GetPlayer()->GetName(), Speed);
1118
1119    chr->SetSpeed(MOVE_RUN,Speed,true);
1120
1121    return true;
1122}
1123
1124//Edit Player Swim Speed
1125bool ChatHandler::HandleModifySwimCommand(const char* args)
1126{
1127    if (!*args)
1128        return false;
1129
1130    float Swim = (float)atof((char*)args);
1131
1132    if (Swim > 10.0f || Swim < 0.01f)
1133    {
1134        SendSysMessage(LANG_BAD_VALUE);
1135        SetSentErrorMessage(true);
1136        return false;
1137    }
1138
1139    Player *chr = getSelectedPlayer();
1140    if (chr == NULL)
1141    {
1142        SendSysMessage(LANG_NO_CHAR_SELECTED);
1143        SetSentErrorMessage(true);
1144        return false;
1145    }
1146
1147    if(chr->isInFlight())
1148    {
1149        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1150        SetSentErrorMessage(true);
1151        return false;
1152    }
1153
1154    PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
1155
1156    if(chr != m_session->GetPlayer())
1157        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_SWIM_SPEED_CHANGED), m_session->GetPlayer()->GetName(), Swim);
1158
1159    chr->SetSpeed(MOVE_SWIM,Swim,true);
1160
1161    return true;
1162}
1163
1164//Edit Player Walk Speed
1165bool ChatHandler::HandleModifyBWalkCommand(const char* args)
1166{
1167    if (!*args)
1168        return false;
1169
1170    float BSpeed = (float)atof((char*)args);
1171
1172    if (BSpeed > 10.0f || BSpeed < 0.1f)
1173    {
1174        SendSysMessage(LANG_BAD_VALUE);
1175        SetSentErrorMessage(true);
1176        return false;
1177    }
1178
1179    Player *chr = getSelectedPlayer();
1180    if (chr == NULL)
1181    {
1182        SendSysMessage(LANG_NO_CHAR_SELECTED);
1183        SetSentErrorMessage(true);
1184        return false;
1185    }
1186
1187    if(chr->isInFlight())
1188    {
1189        PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1190        SetSentErrorMessage(true);
1191        return false;
1192    }
1193
1194    PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
1195
1196    if(chr != m_session->GetPlayer())
1197        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_BACK_SPEED_CHANGED), m_session->GetPlayer()->GetName(), BSpeed);
1198
1199    chr->SetSpeed(MOVE_WALKBACK,BSpeed,true);
1200
1201    return true;
1202}
1203
1204//Edit Player Fly
1205bool ChatHandler::HandleModifyFlyCommand(const char* args)
1206{
1207    if (!*args)
1208        return false;
1209
1210    float FSpeed = (float)atof((char*)args);
1211
1212    if (FSpeed > 10.0f || FSpeed < 0.1f)
1213    {
1214        SendSysMessage(LANG_BAD_VALUE);
1215        SetSentErrorMessage(true);
1216        return false;
1217    }
1218
1219    Player *chr = getSelectedPlayer();
1220    if (chr == NULL)
1221    {
1222        SendSysMessage(LANG_NO_CHAR_SELECTED);
1223        SetSentErrorMessage(true);
1224        return false;
1225    }
1226
1227    PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName());
1228
1229    if(chr != m_session->GetPlayer())
1230        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_FLY_SPEED_CHANGED), m_session->GetPlayer()->GetName(), FSpeed);
1231
1232    chr->SetSpeed(MOVE_FLY,FSpeed,true);
1233
1234    return true;
1235}
1236
1237//Edit Player Scale
1238bool ChatHandler::HandleModifyScaleCommand(const char* args)
1239{
1240    if (!*args)
1241        return false;
1242
1243    float Scale = (float)atof((char*)args);
1244    if (Scale > 10.0f || Scale <= 0.0f)
1245    {
1246        SendSysMessage(LANG_BAD_VALUE);
1247        SetSentErrorMessage(true);
1248        return false;
1249    }
1250
1251    Player *chr = getSelectedPlayer();
1252    if (chr == NULL)
1253    {
1254        SendSysMessage(LANG_NO_CHAR_SELECTED);
1255        SetSentErrorMessage(true);
1256        return false;
1257    }
1258
1259    PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
1260
1261    if(chr != m_session->GetPlayer())
1262        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_SIZE_CHANGED), m_session->GetPlayer()->GetName(), Scale);
1263
1264    chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
1265
1266    return true;
1267}
1268
1269//Enable Player mount
1270bool ChatHandler::HandleModifyMountCommand(const char* args)
1271{
1272    if(!*args)
1273        return false;
1274
1275    uint16 mId = 1147;
1276    float speed = (float)15;
1277    uint32 num = 0;
1278
1279    num = atoi((char*)args);
1280    switch(num)
1281    {
1282        case 1:
1283            mId=14340;
1284            break;
1285        case 2:
1286            mId=4806;
1287            break;
1288        case 3:
1289            mId=6471;
1290            break;
1291        case 4:
1292            mId=12345;
1293            break;
1294        case 5:
1295            mId=6472;
1296            break;
1297        case 6:
1298            mId=6473;
1299            break;
1300        case 7:
1301            mId=10670;
1302            break;
1303        case 8:
1304            mId=10719;
1305            break;
1306        case 9:
1307            mId=10671;
1308            break;
1309        case 10:
1310            mId=10672;
1311            break;
1312        case 11:
1313            mId=10720;
1314            break;
1315        case 12:
1316            mId=14349;
1317            break;
1318        case 13:
1319            mId=11641;
1320            break;
1321        case 14:
1322            mId=12244;
1323            break;
1324        case 15:
1325            mId=12242;
1326            break;
1327        case 16:
1328            mId=14578;
1329            break;
1330        case 17:
1331            mId=14579;
1332            break;
1333        case 18:
1334            mId=14349;
1335            break;
1336        case 19:
1337            mId=12245;
1338            break;
1339        case 20:
1340            mId=14335;
1341            break;
1342        case 21:
1343            mId=207;
1344            break;
1345        case 22:
1346            mId=2328;
1347            break;
1348        case 23:
1349            mId=2327;
1350            break;
1351        case 24:
1352            mId=2326;
1353            break;
1354        case 25:
1355            mId=14573;
1356            break;
1357        case 26:
1358            mId=14574;
1359            break;
1360        case 27:
1361            mId=14575;
1362            break;
1363        case 28:
1364            mId=604;
1365            break;
1366        case 29:
1367            mId=1166;
1368            break;
1369        case 30:
1370            mId=2402;
1371            break;
1372        case 31:
1373            mId=2410;
1374            break;
1375        case 32:
1376            mId=2409;
1377            break;
1378        case 33:
1379            mId=2408;
1380            break;
1381        case 34:
1382            mId=2405;
1383            break;
1384        case 35:
1385            mId=14337;
1386            break;
1387        case 36:
1388            mId=6569;
1389            break;
1390        case 37:
1391            mId=10661;
1392            break;
1393        case 38:
1394            mId=10666;
1395            break;
1396        case 39:
1397            mId=9473;
1398            break;
1399        case 40:
1400            mId=9476;
1401            break;
1402        case 41:
1403            mId=9474;
1404            break;
1405        case 42:
1406            mId=14374;
1407            break;
1408        case 43:
1409            mId=14376;
1410            break;
1411        case 44:
1412            mId=14377;
1413            break;
1414        case 45:
1415            mId=2404;
1416            break;
1417        case 46:
1418            mId=2784;
1419            break;
1420        case 47:
1421            mId=2787;
1422            break;
1423        case 48:
1424            mId=2785;
1425            break;
1426        case 49:
1427            mId=2736;
1428            break;
1429        case 50:
1430            mId=2786;
1431            break;
1432        case 51:
1433            mId=14347;
1434            break;
1435        case 52:
1436            mId=14346;
1437            break;
1438        case 53:
1439            mId=14576;
1440            break;
1441        case 54:
1442            mId=9695;
1443            break;
1444        case 55:
1445            mId=9991;
1446            break;
1447        case 56:
1448            mId=6448;
1449            break;
1450        case 57:
1451            mId=6444;
1452            break;
1453        case 58:
1454            mId=6080;
1455            break;
1456        case 59:
1457            mId=6447;
1458            break;
1459        case 60:
1460            mId=4805;
1461            break;
1462        case 61:
1463            mId=9714;
1464            break;
1465        case 62:
1466            mId=6448;
1467            break;
1468        case 63:
1469            mId=6442;
1470            break;
1471        case 64:
1472            mId=14632;
1473            break;
1474        case 65:
1475            mId=14332;
1476            break;
1477        case 66:
1478            mId=14331;
1479            break;
1480        case 67:
1481            mId=8469;
1482            break;
1483        case 68:
1484            mId=2830;
1485            break;
1486        case 69:
1487            mId=2346;
1488            break;
1489        default:
1490            SendSysMessage(LANG_NO_MOUNT);
1491            SetSentErrorMessage(true);
1492            return false;
1493    }
1494
1495    Player *chr = getSelectedPlayer();
1496    if (chr == NULL)
1497    {
1498        SendSysMessage(LANG_NO_CHAR_SELECTED);
1499        SetSentErrorMessage(true);
1500        return false;
1501    }
1502
1503    PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1504
1505    if(chr != m_session->GetPlayer())
1506        ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_MOUNT_GIVED), m_session->GetPlayer()->GetName());
1507
1508    chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
1509    chr->Mount(mId);
1510
1511    WorldPacket data( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+1+4) );
1512    data.append(chr->GetPackGUID());
1513    data << (uint32)0;
1514    data << (uint8)0;                                       //new 2.1.0
1515    data << float(speed);
1516    chr->SendMessageToSet( &data, true );
1517
1518    data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
1519    data.append(chr->GetPackGUID());
1520    data << (uint32)0;
1521    data << float(speed);
1522    chr->SendMessageToSet( &data, true );
1523
1524    return true;
1525}
1526
1527//Edit Player money
1528bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1529{
1530    if (!*args)
1531        return false;
1532
1533    Player *chr = getSelectedPlayer();
1534    if (chr == NULL)
1535    {
1536        SendSysMessage(LANG_NO_CHAR_SELECTED);
1537        SetSentErrorMessage(true);
1538        return false;
1539    }
1540
1541    int32 addmoney = atoi((char*)args);
1542
1543    uint32 moneyuser = chr->GetMoney();
1544
1545    if(addmoney < 0)
1546    {
1547        int32 newmoney = moneyuser + addmoney;
1548
1549        sLog.outDetail(GetTrinityString(LANG_CURRENT_MONEY), moneyuser, addmoney, newmoney);
1550        if(newmoney <= 0 )
1551        {
1552            PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1553
1554            if(chr != m_session->GetPlayer())
1555                ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_ALL_MONEY_GONE), m_session->GetPlayer()->GetName());
1556
1557            chr->SetMoney(0);
1558        }
1559        else
1560        {
1561            PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1562            if(chr != m_session->GetPlayer())
1563                ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_MONEY_TAKEN), m_session->GetPlayer()->GetName(), abs(addmoney));
1564            chr->SetMoney( newmoney );
1565        }
1566    }
1567    else
1568    {
1569        PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1570        if(chr != m_session->GetPlayer())
1571            ChatHandler(chr).PSendSysMessage(ChatHandler(chr).GetTrinityString(LANG_YOURS_MONEY_GIVEN), m_session->GetPlayer()->GetName(), addmoney);
1572        chr->ModifyMoney( addmoney );
1573    }
1574
1575    sLog.outDetail(GetTrinityString(LANG_NEW_MONEY), moneyuser, addmoney, chr->GetMoney() );
1576
1577    return true;
1578}
1579
1580//Edit Player field
1581bool ChatHandler::HandleModifyBitCommand(const char* args)
1582{
1583    if( !*args )
1584        return false;
1585
1586    Player *chr = getSelectedPlayer();
1587    if (chr == NULL)
1588    {
1589        SendSysMessage(LANG_NO_CHAR_SELECTED);
1590        SetSentErrorMessage(true);
1591        return false;
1592    }
1593
1594    char* pField = strtok((char*)args, " ");
1595    if (!pField)
1596        return false;
1597
1598    char* pBit = strtok(NULL, " ");
1599    if (!pBit)
1600        return false;
1601
1602    uint16 field = atoi(pField);
1603    uint32 bit   = atoi(pBit);
1604
1605    if (field < 1 || field >= PLAYER_END)
1606    {
1607        SendSysMessage(LANG_BAD_VALUE);
1608        SetSentErrorMessage(true);
1609        return false;
1610    }
1611
1612    if (bit < 1 || bit > 32)
1613    {
1614        SendSysMessage(LANG_BAD_VALUE);
1615        SetSentErrorMessage(true);
1616        return false;
1617    }
1618
1619    if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1620    {
1621        chr->RemoveFlag( field, (1<<(bit-1)) );
1622        PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1623    }
1624    else
1625    {
1626        chr->SetFlag( field, (1<<(bit-1)) );
1627        PSendSysMessage(LANG_SET_BIT, bit, field);
1628    }
1629
1630    return true;
1631}
1632
1633bool ChatHandler::HandleModifyHonorCommand (const char* args)
1634{
1635    if (!*args)
1636        return false;
1637
1638    Player *target = getSelectedPlayer();
1639    if(!target)
1640    {
1641        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1642        SetSentErrorMessage(true);
1643        return false;
1644    }
1645
1646    int32 amount = (uint32)atoi(args);
1647
1648    target->ModifyHonorPoints(amount);
1649
1650    PSendSysMessage(LANG_COMMAND_MODIFY_HONOR, target->GetName(), target->GetHonorPoints());
1651
1652    return true;
1653}
1654
1655bool ChatHandler::HandleTeleCommand(const char * args)
1656{
1657    if(!*args)
1658        return false;
1659
1660    Player* _player = m_session->GetPlayer();
1661
1662    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
1663    GameTele const* tele = extractGameTeleFromLink((char*)args);
1664    if (!tele)
1665    {
1666        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1667        SetSentErrorMessage(true);
1668        return false;
1669    }
1670
1671    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
1672    if(!me || me->IsBattleGroundOrArena())
1673    {
1674        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
1675        SetSentErrorMessage(true);
1676        return false;
1677    }
1678
1679    // stop flight if need
1680    if(_player->isInFlight())
1681    {
1682        _player->GetMotionMaster()->MovementExpired();
1683        _player->m_taxi.ClearTaxiDestinations();
1684    }
1685    // save only in non-flight case
1686    else
1687        _player->SaveRecallPosition();
1688
1689    _player->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
1690    return true;
1691}
1692
1693bool ChatHandler::HandleLookupAreaCommand(const char* args)
1694{
1695    if (!*args)
1696        return false;
1697
1698    std::string namepart = args;
1699    std::wstring wnamepart;
1700
1701    if (!Utf8toWStr (namepart,wnamepart))
1702        return false;
1703
1704    uint32 counter = 0;                                     // Counter for figure out that we found smth.
1705
1706    // converting string that we try to find to lower case
1707    wstrToLower (wnamepart);
1708
1709    // Search in AreaTable.dbc
1710    for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows (); ++areaflag)
1711    {
1712        AreaTableEntry const *areaEntry = sAreaStore.LookupEntry (areaflag);
1713        if (areaEntry)
1714        {
1715            int loc = m_session ? m_session->GetSessionDbcLocale () : sWorld.GetDefaultDbcLocale();
1716            std::string name = areaEntry->area_name[loc];
1717            if (name.empty())
1718                continue;
1719
1720            if (!Utf8FitTo (name, wnamepart))
1721            {
1722                loc = 0;
1723                for(; loc < MAX_LOCALE; ++loc)
1724                {
1725                    if (m_session && loc==m_session->GetSessionDbcLocale ())
1726                        continue;
1727
1728                    name = areaEntry->area_name[loc];
1729                    if (name.empty ())
1730                        continue;
1731
1732                    if (Utf8FitTo (name, wnamepart))
1733                        break;
1734                }
1735            }
1736
1737            if (loc < MAX_LOCALE)
1738            {
1739                // send area in "id - [name]" format
1740                std::ostringstream ss;
1741                if (m_session)
1742                                        ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << " " << localeNames[loc]<< "]|h|r";
1743                                else
1744                                        ss << areaEntry->ID << " - " << name << " " << localeNames[loc];
1745
1746                SendSysMessage (ss.str ().c_str());
1747
1748                ++counter;
1749            }
1750        }
1751    }
1752    if (counter == 0)                                      // if counter == 0 then we found nth
1753        SendSysMessage (LANG_COMMAND_NOAREAFOUND);
1754    return true;
1755}
1756
1757//Find tele in game_tele order by name
1758bool ChatHandler::HandleLookupTeleCommand(const char * args)
1759{
1760    if(!*args)
1761    {
1762        SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1763        SetSentErrorMessage(true);
1764        return false;
1765    }
1766
1767    char const* str = strtok((char*)args, " ");
1768    if(!str)
1769        return false;
1770
1771    std::string namepart = str;
1772    std::wstring wnamepart;
1773
1774    if(!Utf8toWStr(namepart,wnamepart))
1775        return false;
1776
1777    // converting string that we try to find to lower case
1778    wstrToLower( wnamepart );
1779
1780    std::ostringstream reply;
1781
1782        GameTeleMap const & teleMap = objmgr.GetGameTeleMap();
1783    for(GameTeleMap::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
1784    {
1785        GameTele const* tele = &itr->second;
1786
1787        if(tele->wnameLow.find(wnamepart) == std::wstring::npos)
1788            continue;
1789
1790        if (m_session)
1791                        reply << "  |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
1792                else
1793                        reply << "  " << itr->first << " " << tele->name << "\n";
1794    }
1795
1796    if(reply.str().empty())
1797        SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1798    else
1799        PSendSysMessage(LANG_COMMAND_TELE_LOCATION,reply.str().c_str());
1800
1801    return true;
1802}
1803
1804//Enable\Dissable accept whispers (for GM)
1805bool ChatHandler::HandleWhispersCommand(const char* args)
1806{
1807    if(!*args)
1808    {
1809        PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ?  GetTrinityString(LANG_ON) : GetTrinityString(LANG_OFF));
1810        return true;
1811    }
1812
1813    std::string argstr = (char*)args;
1814    // whisper on
1815    if (argstr == "on")
1816    {
1817        m_session->GetPlayer()->SetAcceptWhispers(true);
1818        SendSysMessage(LANG_COMMAND_WHISPERON);
1819        return true;
1820    }
1821
1822    // whisper off
1823    if (argstr == "off")
1824    {
1825        m_session->GetPlayer()->SetAcceptWhispers(false);
1826        SendSysMessage(LANG_COMMAND_WHISPEROFF);
1827        return true;
1828    }
1829
1830    SendSysMessage(LANG_USE_BOL);
1831    SetSentErrorMessage(true);
1832    return false;
1833}
1834
1835//Play sound
1836bool ChatHandler::HandlePlaySoundCommand(const char* args)
1837{
1838    // USAGE: .debug playsound #soundid
1839    // #soundid - ID decimal number from SoundEntries.dbc (1st column)
1840    // this file have about 5000 sounds.
1841    // In this realization only caller can hear this sound.
1842    if( *args )
1843    {
1844        uint32 dwSoundId = atoi((char*)args);
1845
1846        if( !sSoundEntriesStore.LookupEntry(dwSoundId) )
1847        {
1848            PSendSysMessage(LANG_SOUND_NOT_EXIST, dwSoundId);
1849            SetSentErrorMessage(true);
1850            return false;
1851        }
1852
1853        WorldPacket data(SMSG_PLAY_OBJECT_SOUND,4+8);
1854        data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
1855        m_session->SendPacket(&data);
1856
1857        PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
1858        return true;
1859    }
1860
1861    return false;
1862}
1863
1864//Save all players in the world
1865bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
1866{
1867    ObjectAccessor::Instance().SaveAllPlayers();
1868    SendSysMessage(LANG_PLAYERS_SAVED);
1869    return true;
1870}
1871
1872//Send mail by command
1873bool ChatHandler::HandleSendMailCommand(const char* args)
1874{
1875    if(!*args)
1876        return false;
1877
1878    // format: name "subject text" "mail text" item1[:count1] item2[:count2] ... item12[:count12]
1879
1880    char* pName = strtok((char*)args, " ");
1881    if(!pName)
1882        return false;
1883
1884    char* tail1 = strtok(NULL, "");
1885    if(!tail1)
1886        return false;
1887
1888    char* msgSubject;
1889    if(*tail1=='"')
1890        msgSubject = strtok(tail1+1, "\"");
1891    else
1892    {
1893        char* space = strtok(tail1, "\"");
1894        if(!space)
1895            return false;
1896        msgSubject = strtok(NULL, "\"");
1897    }
1898
1899    if (!msgSubject)
1900        return false;
1901
1902    char* tail2 = strtok(NULL, "");
1903    if(!tail2)
1904        return false;
1905
1906    char* msgText;
1907    if(*tail2=='"')
1908        msgText = strtok(tail2+1, "\"");
1909    else
1910    {
1911        char* space = strtok(tail2, "\"");
1912        if(!space)
1913            return false;
1914        msgText = strtok(NULL, "\"");
1915    }
1916
1917    if (!msgText)
1918        return false;
1919
1920    // pName, msgSubject, msgText isn't NUL after prev. check
1921    std::string name    = pName;
1922    std::string subject = msgSubject;
1923    std::string text    = msgText;
1924
1925    // extract items
1926    typedef std::pair<uint32,uint32> ItemPair;
1927    typedef std::list< ItemPair > ItemPairs;
1928    ItemPairs items;
1929
1930    // get all tail string
1931    char* tail = strtok(NULL, "");
1932
1933    // get from tail next item str
1934    while(char* itemStr = strtok(tail, " "))
1935    {
1936        // and get new tail
1937        tail = strtok(NULL, "");
1938
1939        // parse item str
1940        char* itemIdStr = strtok(itemStr, ":");
1941        char* itemCountStr = strtok(NULL, " ");
1942       
1943        uint32 item_id = atoi(itemIdStr);
1944        if(!item_id)
1945            return false;
1946
1947        ItemPrototype const* item_proto = objmgr.GetItemPrototype(item_id);
1948        if(!item_proto)
1949        {
1950            PSendSysMessage(LANG_COMMAND_ITEMIDINVALID, item_id);
1951            SetSentErrorMessage(true);
1952            return false;
1953        }
1954
1955        uint32 item_count = itemCountStr ? atoi(itemCountStr) : 1;
1956        if(item_count < 1 || item_proto->MaxCount && item_count > item_proto->MaxCount)
1957        {
1958            PSendSysMessage(LANG_COMMAND_INVALID_ITEM_COUNT, item_count,item_id);
1959            SetSentErrorMessage(true);
1960            return false;
1961        }
1962
1963        while(item_count > item_proto->Stackable)
1964        {
1965            items.push_back(ItemPair(item_id,item_proto->Stackable));
1966            item_count -= item_proto->Stackable;
1967        }
1968
1969        items.push_back(ItemPair(item_id,item_count));
1970
1971        if(items.size() > MAX_MAIL_ITEMS)
1972        {
1973            PSendSysMessage(LANG_COMMAND_MAIL_ITEMS_LIMIT, MAX_MAIL_ITEMS);
1974            SetSentErrorMessage(true);
1975            return false;
1976        }
1977    }
1978
1979    if(!normalizePlayerName(name))
1980    {
1981        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1982        SetSentErrorMessage(true);
1983        return false;
1984    }
1985
1986    uint64 receiver_guid = objmgr.GetPlayerGUIDByName(name);
1987    if(!receiver_guid)
1988    {
1989        SendSysMessage(LANG_PLAYER_NOT_FOUND);
1990        SetSentErrorMessage(true);
1991        return false;
1992    }
1993
1994    uint32 mailId = objmgr.GenerateMailID();
1995    uint32 sender_guidlo = m_session->GetPlayer()->GetGUIDLow();
1996    uint32 messagetype = MAIL_NORMAL;
1997    uint32 stationery = MAIL_STATIONERY_GM;
1998    uint32 itemTextId = 0;
1999    if (!text.empty())
2000    {
2001        itemTextId = objmgr.CreateItemText( text );
2002    }
2003
2004    Player *receiver = objmgr.GetPlayer(receiver_guid);
2005
2006    // fill mail
2007    MailItemsInfo mi;                                       // item list preparing
2008
2009    for(ItemPairs::const_iterator itr = items.begin(); itr != items.end(); ++itr)
2010    {
2011        if(Item* item = Item::CreateItem(itr->first,itr->second,m_session->GetPlayer()))
2012        {
2013            item->SaveToDB();                               // save for prevent lost at next mail load, if send fail then item will deleted
2014            mi.AddItem(item->GetGUIDLow(), item->GetEntry(), item);
2015        }
2016    }
2017
2018    WorldSession::SendMailTo(receiver,messagetype, stationery, sender_guidlo, GUID_LOPART(receiver_guid), subject, itemTextId, &mi, 0, 0, MAIL_CHECK_MASK_NONE);
2019
2020    PSendSysMessage(LANG_MAIL_SENT, name.c_str());
2021    return true;
2022}
2023
2024// teleport player to given game_tele.entry
2025bool ChatHandler::HandleNameTeleCommand(const char * args)
2026{
2027    if(!*args)
2028        return false;
2029
2030    char* pName = strtok((char*)args, " ");
2031
2032    if(!pName)
2033        return false;
2034
2035    std::string name = pName;
2036
2037    if(!normalizePlayerName(name))
2038    {
2039        SendSysMessage(LANG_PLAYER_NOT_FOUND);
2040        SetSentErrorMessage(true);
2041        return false;
2042    }
2043
2044    char* tail = strtok(NULL, "");
2045    if(!tail)
2046        return false;
2047
2048    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2049    GameTele const* tele = extractGameTeleFromLink(tail);
2050    if(!tele)
2051    {
2052        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2053        SetSentErrorMessage(true);
2054        return false;
2055    }
2056
2057    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
2058    if(!me || me->IsBattleGroundOrArena())
2059    {
2060        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
2061        SetSentErrorMessage(true);
2062        return false;
2063    }
2064
2065    Player *chr = objmgr.GetPlayer(name.c_str());
2066    if (chr)
2067    {
2068
2069        if(chr->IsBeingTeleported()==true)
2070        {
2071            PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
2072            SetSentErrorMessage(true);
2073            return false;
2074        }
2075
2076        PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", tele->name.c_str());
2077
2078        if (m_session)
2079                {
2080                        if(m_session->GetPlayer()->IsVisibleGloballyFor(chr))
2081                                ChatHandler(chr).PSendSysMessage(LANG_TELEPORTED_TO_BY, m_session->GetPlayer()->GetName());
2082                }
2083                else
2084                        ChatHandler(chr).SendSysMessage(LANG_TELEPORTED_TO_BY_CONSOLE);
2085
2086        // stop flight if need
2087        if(chr->isInFlight())
2088        {
2089            chr->GetMotionMaster()->MovementExpired();
2090            chr->m_taxi.ClearTaxiDestinations();
2091        }
2092        // save only in non-flight case
2093        else
2094            chr->SaveRecallPosition();
2095
2096        chr->TeleportTo(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation);
2097    }
2098    else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
2099    {
2100        PSendSysMessage(LANG_TELEPORTING_TO, name.c_str(), GetTrinityString(LANG_OFFLINE), tele->name.c_str());
2101        Player::SavePositionInDB(tele->mapId,tele->position_x,tele->position_y,tele->position_z,tele->orientation,MapManager::Instance().GetZoneId(tele->mapId,tele->position_x,tele->position_y),guid);
2102    }
2103    else
2104        PSendSysMessage(LANG_NO_PLAYER, name.c_str());
2105
2106    return true;
2107}
2108
2109//Teleport group to given game_tele.entry
2110bool ChatHandler::HandleGroupTeleCommand(const char * args)
2111{
2112    if(!*args)
2113        return false;
2114
2115    Player *player = getSelectedPlayer();
2116    if (!player)
2117    {
2118        SendSysMessage(LANG_NO_CHAR_SELECTED);
2119        SetSentErrorMessage(true);
2120        return false;
2121    }
2122
2123    // id, or string, or [name] Shift-click form |color|Htele:id|h[name]|h|r
2124    GameTele const* tele = extractGameTeleFromLink((char*)args);
2125    if(!tele)
2126    {
2127        SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
2128        SetSentErrorMessage(true);
2129        return false;
2130    }
2131
2132    MapEntry const * me = sMapStore.LookupEntry(tele->mapId);
2133    if(!me || me->IsBattleGroundOrArena())
2134    {
2135        SendSysMessage(LANG_CANNOT_TELE_TO_BG);
2136        SetSentErrorMessage(true);
2137        return false;
2138    }
2139    Group *grp = player->GetGroup();
2140    if(!grp)
2141    {
2142        PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2143        SetSentErrorMessage(true);
2144        return false;
2145    }
2146
2147    for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2148    {
2149        Player *pl = itr->getSource();
2150
2151        if(!pl || !pl->GetSession() )
2152            continue;
2153
2154        if(pl->IsBeingTeleported())
2155        {
2156            PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2157            continue;
2158        }
2159
2160        PSendSysMessage(LANG_TELEPORTING_TO, pl->GetName(),"", tele->name.c_str());
2161
2162        if (m_session->GetPlayer() != pl && m_session->GetPlayer()->IsVisibleGloballyFor(pl))
2163            ChatHandler(pl).PSendSysMessage(LANG_TELEPORTED_TO_BY, m_session->GetPlayer()->GetName());
2164
2165        // stop flight if need
2166        if(pl->isInFlight())
2167        {
2168            pl->GetMotionMaster()->MovementExpired();
2169            pl->m_taxi.ClearTaxiDestinations();
2170        }
2171        // save only in non-flight case
2172        else
2173            pl->SaveRecallPosition();
2174
2175        pl->TeleportTo(tele->mapId, tele->position_x, tele->position_y, tele->position_z, tele->orientation);
2176    }
2177
2178    return true;
2179}
2180
2181//Summon group of player
2182bool ChatHandler::HandleGroupgoCommand(const char* args)
2183{
2184    if(!*args)
2185        return false;
2186
2187    std::string name = args;
2188
2189    if(!normalizePlayerName(name))
2190    {
2191        SendSysMessage(LANG_PLAYER_NOT_FOUND);
2192        SetSentErrorMessage(true);
2193        return false;
2194    }
2195
2196    Player *player = objmgr.GetPlayer(name.c_str());
2197    if (!player)
2198    {
2199        PSendSysMessage(LANG_NO_PLAYER, args);
2200        SetSentErrorMessage(true);
2201        return false;
2202    }
2203
2204    Group *grp = player->GetGroup();
2205
2206    if(!grp)
2207    {
2208        PSendSysMessage(LANG_NOT_IN_GROUP,player->GetName());
2209        SetSentErrorMessage(true);
2210        return false;
2211    }
2212
2213    Map* gmMap = MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(),m_session->GetPlayer());
2214    bool to_instance =  gmMap->Instanceable();
2215
2216    // we are in instance, and can summon only player in our group with us as lead
2217    if ( to_instance && (
2218        !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
2219        (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ) )
2220        // the last check is a bit excessive, but let it be, just in case
2221    {
2222        SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
2223        SetSentErrorMessage(true);
2224        return false;
2225    }
2226
2227    for(GroupReference *itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
2228    {
2229        Player *pl = itr->getSource();
2230
2231        if(!pl || pl==m_session->GetPlayer() || !pl->GetSession() )
2232            continue;
2233
2234        if(pl->IsBeingTeleported()==true)
2235        {
2236            PSendSysMessage(LANG_IS_TELEPORTED, pl->GetName());
2237            SetSentErrorMessage(true);
2238            return false;
2239        }
2240
2241        if (to_instance)
2242        {
2243            Map* plMap = MapManager::Instance().GetMap(pl->GetMapId(),pl);
2244
2245            if ( plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId() )
2246            {
2247                // cannot summon from instance to instance
2248                PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,pl->GetName());
2249                SetSentErrorMessage(true);
2250                return false;
2251            }
2252        }
2253
2254        PSendSysMessage(LANG_SUMMONING, pl->GetName(),"");
2255
2256        if (m_session->GetPlayer()->IsVisibleGloballyFor(pl))
2257            ChatHandler(pl).PSendSysMessage(LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
2258
2259        // stop flight if need
2260        if(pl->isInFlight())
2261        {
2262            pl->GetMotionMaster()->MovementExpired();
2263            pl->m_taxi.ClearTaxiDestinations();
2264        }
2265        // save only in non-flight case
2266        else
2267            pl->SaveRecallPosition();
2268
2269        // before GM
2270        float x,y,z;
2271        m_session->GetPlayer()->GetClosePoint(x,y,z,pl->GetObjectSize());
2272        pl->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,pl->GetOrientation());
2273    }
2274
2275    return true;
2276}
2277
2278//teleport at coordinates
2279bool ChatHandler::HandleGoXYCommand(const char* args)
2280{
2281    if(!*args)
2282        return false;
2283
2284    Player* _player = m_session->GetPlayer();
2285
2286    char* px = strtok((char*)args, " ");
2287    char* py = strtok(NULL, " ");
2288    char* pmapid = strtok(NULL, " ");
2289
2290    if (!px || !py)
2291        return false;
2292
2293    float x = (float)atof(px);
2294    float y = (float)atof(py);
2295    uint32 mapid;
2296    if (pmapid)
2297        mapid = (uint32)atoi(pmapid);
2298    else mapid = _player->GetMapId();
2299
2300    if(!MapManager::IsValidMapCoord(mapid,x,y))
2301    {
2302        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2303        SetSentErrorMessage(true);
2304        return false;
2305    }
2306
2307    // stop flight if need
2308    if(_player->isInFlight())
2309    {
2310        _player->GetMotionMaster()->MovementExpired();
2311        _player->m_taxi.ClearTaxiDestinations();
2312    }
2313    // save only in non-flight case
2314    else
2315        _player->SaveRecallPosition();
2316
2317    Map const *map = MapManager::Instance().GetBaseMap(mapid);
2318    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2319
2320    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2321
2322    return true;
2323}
2324
2325//teleport at coordinates, including Z
2326bool ChatHandler::HandleGoXYZCommand(const char* args)
2327{
2328    if(!*args)
2329        return false;
2330
2331    Player* _player = m_session->GetPlayer();
2332
2333    char* px = strtok((char*)args, " ");
2334    char* py = strtok(NULL, " ");
2335    char* pz = strtok(NULL, " ");
2336    char* pmapid = strtok(NULL, " ");
2337
2338    if (!px || !py || !pz)
2339        return false;
2340
2341    float x = (float)atof(px);
2342    float y = (float)atof(py);
2343    float z = (float)atof(pz);
2344    uint32 mapid;
2345    if (pmapid)
2346        mapid = (uint32)atoi(pmapid);
2347    else
2348        mapid = _player->GetMapId();
2349
2350    if(!MapManager::IsValidMapCoord(mapid,x,y,z))
2351    {
2352        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2353        SetSentErrorMessage(true);
2354        return false;
2355    }
2356
2357    // stop flight if need
2358    if(_player->isInFlight())
2359    {
2360        _player->GetMotionMaster()->MovementExpired();
2361        _player->m_taxi.ClearTaxiDestinations();
2362    }
2363    // save only in non-flight case
2364    else
2365        _player->SaveRecallPosition();
2366
2367    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2368
2369    return true;
2370}
2371
2372//teleport at coordinates
2373bool ChatHandler::HandleGoZoneXYCommand(const char* args)
2374{
2375    if(!*args)
2376        return false;
2377
2378    Player* _player = m_session->GetPlayer();
2379
2380    char* px = strtok((char*)args, " ");
2381    char* py = strtok(NULL, " ");
2382    char* tail = strtok(NULL,"");
2383
2384    char* cAreaId = extractKeyFromLink(tail,"Harea");       // string or [name] Shift-click form |color|Harea:area_id|h[name]|h|r
2385
2386    if (!px || !py)
2387        return false;
2388
2389    float x = (float)atof(px);
2390    float y = (float)atof(py);
2391    uint32 areaid = cAreaId ? (uint32)atoi(cAreaId) : _player->GetZoneId();
2392
2393    AreaTableEntry const* areaEntry = GetAreaEntryByAreaID(areaid);
2394
2395    if( x<0 || x>100 || y<0 || y>100 || !areaEntry )
2396    {
2397        PSendSysMessage(LANG_INVALID_ZONE_COORD,x,y,areaid);
2398        SetSentErrorMessage(true);
2399        return false;
2400    }
2401
2402    // update to parent zone if exist (client map show only zones without parents)
2403    AreaTableEntry const* zoneEntry = areaEntry->zone ? GetAreaEntryByAreaID(areaEntry->zone) : areaEntry;
2404
2405    Map const *map = MapManager::Instance().GetBaseMap(zoneEntry->mapid);
2406
2407    if(map->Instanceable())
2408    {
2409        PSendSysMessage(LANG_INVALID_ZONE_MAP,areaEntry->ID,areaEntry->area_name[m_session->GetSessionDbcLocale()],map->GetId(),map->GetMapName());
2410        SetSentErrorMessage(true);
2411        return false;
2412    }
2413
2414    Zone2MapCoordinates(x,y,zoneEntry->ID);
2415
2416    if(!MapManager::IsValidMapCoord(zoneEntry->mapid,x,y))
2417    {
2418        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,zoneEntry->mapid);
2419        SetSentErrorMessage(true);
2420        return false;
2421    }
2422
2423    // stop flight if need
2424    if(_player->isInFlight())
2425    {
2426        _player->GetMotionMaster()->MovementExpired();
2427        _player->m_taxi.ClearTaxiDestinations();
2428    }
2429    // save only in non-flight case
2430    else
2431        _player->SaveRecallPosition();
2432
2433    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2434    _player->TeleportTo(zoneEntry->mapid, x, y, z, _player->GetOrientation());
2435
2436    return true;
2437}
2438
2439//teleport to grid
2440bool ChatHandler::HandleGoGridCommand(const char* args)
2441{
2442    if(!*args)    return false;
2443    Player* _player = m_session->GetPlayer();
2444
2445    char* px = strtok((char*)args, " ");
2446    char* py = strtok(NULL, " ");
2447    char* pmapid = strtok(NULL, " ");
2448
2449    if (!px || !py)
2450        return false;
2451
2452    float grid_x = (float)atof(px);
2453    float grid_y = (float)atof(py);
2454    uint32 mapid;
2455    if (pmapid)
2456        mapid = (uint32)atoi(pmapid);
2457    else mapid = _player->GetMapId();
2458
2459    // center of grid
2460    float x = (grid_x-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2461    float y = (grid_y-CENTER_GRID_ID+0.5f)*SIZE_OF_GRIDS;
2462
2463    if(!MapManager::IsValidMapCoord(mapid,x,y))
2464    {
2465        PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
2466        SetSentErrorMessage(true);
2467        return false;
2468    }
2469
2470    // stop flight if need
2471    if(_player->isInFlight())
2472    {
2473        _player->GetMotionMaster()->MovementExpired();
2474        _player->m_taxi.ClearTaxiDestinations();
2475    }
2476    // save only in non-flight case
2477    else
2478        _player->SaveRecallPosition();
2479
2480    Map const *map = MapManager::Instance().GetBaseMap(mapid);
2481    float z = std::max(map->GetHeight(x, y, MAX_HEIGHT), map->GetWaterLevel(x, y));
2482    _player->TeleportTo(mapid, x, y, z, _player->GetOrientation());
2483
2484    return true;
2485}
2486
2487bool ChatHandler::HandleDrunkCommand(const char* args)
2488{
2489    if(!*args)    return false;
2490
2491    uint32 drunklevel = (uint32)atoi(args);
2492    if(drunklevel > 100)
2493        drunklevel = 100;
2494
2495    uint16 drunkMod = drunklevel * 0xFFFF / 100;
2496
2497    m_session->GetPlayer()->SetDrunkValue(drunkMod);
2498
2499    return true;
2500}
Note: See TracBrowser for help on using the browser.