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

Revision 39, 66.4 kB (checked in by yumileroy, 17 years ago)

[svn] * Various small changes here and there.
* Implementing MangChat? IRC system.
* Added new config option, MAX_WHO, can be used to set the limit of characters being sent in a /who request from client.

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