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

Revision 2, 61.7 kB (checked in by yumileroy, 17 years ago)

[svn] * Proper SVN structure

Original author: Neo2003
Date: 2008-10-02 16:23:55-05:00

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