2 * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
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.
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.
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
20 #include "Database/DatabaseEnv.h"
21 #include "WorldPacket.h"
22 #include "WorldSession.h"
24 #include "ObjectMgr.h"
29 #include "MapManager.h"
30 #include "ObjectAccessor.h"
32 #include "RedZoneDistrict.h"
33 #include "Transports.h"
35 #include "VMapFactory.h"
37 bool ChatHandler::HandleSayCommand(const char* args
)
39 uint64 guid
= m_session
->GetPlayer()->GetSelection();
40 Creature
* pCreature
= ObjectAccessor::Instance().GetCreature(*m_session
->GetPlayer(), guid
);
44 SendSysMessage(LANG_SELECT_CREATURE
);
48 pCreature
->Say(args
, LANG_UNIVERSAL
, 0);
53 bool ChatHandler::HandleYellCommand(const char* args
)
55 uint64 guid
= m_session
->GetPlayer()->GetSelection();
56 Creature
* pCreature
= ObjectAccessor::Instance().GetCreature(*m_session
->GetPlayer(), guid
);
60 SendSysMessage(LANG_SELECT_CREATURE
);
64 pCreature
->Yell(args
, LANG_UNIVERSAL
, 0);
69 bool ChatHandler::HandleEmote2Command(const char* args
)
71 uint64 guid
= m_session
->GetPlayer()->GetSelection();
72 Creature
* pCreature
= ObjectAccessor::Instance().GetCreature(*m_session
->GetPlayer(), guid
);
76 SendSysMessage(LANG_SELECT_CREATURE
);
80 pCreature
->TextEmote(args
, 0);
85 bool ChatHandler::HandleWhisperCommand(const char* args
) //WTF? what should it do?
87 char* receiver
= strtok((char*)args
, " ");
88 char* text
= strtok(NULL
, "");
90 uint64 guid
= m_session
->GetPlayer()->GetSelection();
91 Creature
* pCreature
= ObjectAccessor::Instance().GetCreature(*m_session
->GetPlayer(), guid
);
93 if(!pCreature
|| !receiver
|| !text
)
95 SendSysMessage(LANG_SELECT_CREATURE
);
99 pCreature
->Whisper(atol(receiver
), text
);
104 bool ChatHandler::HandleAnnounceCommand(const char* args
)
109 std::string str
= LANG_SYSTEMMESSAGE
;
111 sWorld
.SendWorldText(str
.c_str(), NULL
);
114 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
116 m_session
->GetPlayer()->GetPosition(x
,y
,z
);
118 sprintf(buffer
, "pos %f,%f,%f",x
,y
,z
);
119 vMapManager
->processCommand(buffer
);
124 bool ChatHandler::HandleNotifyCommand(const char* args
)
129 std::string str
= LANG_GLOBAL_NOTIFY
;
132 WorldPacket
data(SMSG_NOTIFICATION
, (str
.size()+1));
134 sWorld
.SendGlobalMessage(&data
);
139 bool ChatHandler::HandleGMOnCommand(const char* args
)
141 m_session
->GetPlayer()->SetGameMaster(true);
142 m_session
->SendNotification("GM mode is ON");
144 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
145 vMapManager
->processCommand("stoplog");
150 bool ChatHandler::HandleGMOffCommand(const char* args
)
152 m_session
->GetPlayer()->SetGameMaster(false);
153 m_session
->SendNotification("GM mode is OFF");
155 VMAP::IVMapManager
*vMapManager
= VMAP::VMapFactory::createOrGetVMapManager();
156 vMapManager
->processCommand("startlog");
161 bool ChatHandler::HandleVisibleCommand(const char* args
)
163 int option
= atoi((char*)args
);
165 if (option
!= 0 && option
!= 1 || !*args
)
167 SendSysMessage(LANG_USE_BOL
);
168 PSendSysMessage(LANG_YOU_ARE
, m_session
->GetPlayer()->isGMVisible() ? LANG_VISIBLE
: LANG_INVISIBLE
);
174 m_session
->GetPlayer()->SetGMVisible(true);
175 m_session
->SendNotification( LANG_INVISIBLE_VISIBLE
);
179 m_session
->SendNotification( LANG_INVISIBLE_INVISIBLE
);
180 m_session
->GetPlayer()->SetGMVisible(false);
186 bool ChatHandler::HandleGPSCommand(const char* args
)
188 WorldObject
*obj
= getSelectedUnit();
192 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE
);
196 CellPair cell_val
= MaNGOS::ComputeCellPair(obj
->GetPositionX(), obj
->GetPositionY());
197 Cell cell
= RedZone::GetZone(cell_val
);
199 PSendSysMultilineMessage(LANG_MAP_POSITION
,
200 obj
->GetMapId(), obj
->GetZoneId(), obj
->GetAreaId(), obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(),
201 obj
->GetOrientation(),cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(),obj
->GetInstanceId());
203 sLog
.outDebug("Player %s GPS call %s %u " LANG_MAP_POSITION
, m_session
->GetPlayer()->GetName(),
204 (obj
->GetTypeId() == TYPEID_PLAYER
? "player" : "creature"), obj
->GetGUIDLow(),
205 obj
->GetMapId(), obj
->GetZoneId(), obj
->GetAreaId(), obj
->GetPositionX(), obj
->GetPositionY(), obj
->GetPositionZ(),
206 obj
->GetOrientation(), cell
.GridX(), cell
.GridY(), cell
.CellX(), cell
.CellY(),obj
->GetInstanceId());
211 bool ChatHandler::HandleNamegoCommand(const char* args
)
213 if(m_session
->GetPlayer()->isInFlight())
215 SendSysMessage(LANG_YOU_IN_FLIGHT
);
222 std::string name
= args
;
223 normalizePlayerName(name
);
224 //sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
226 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
230 if(chr
->IsBeingTeleported()==true)
232 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
236 if(chr
->isInFlight())
238 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
242 if (MapManager::Instance().GetMap(m_session
->GetPlayer()->GetMapId(), m_session
->GetPlayer())->Instanceable())
244 if ( (MapManager::Instance().GetMap(chr
->GetMapId(), chr
)->Instanceable()) &&
245 (MapManager::Instance().GetMap(chr
->GetMapId(), chr
)->GetInstanceId() !=
246 MapManager::Instance().GetMap(m_session
->GetPlayer()->GetMapId(), m_session
->GetPlayer())->GetInstanceId()) )
248 // cannot summon from instance to instance
249 PSendSysMessage(LANG_CANNOT_INST_INST
);
253 // we are in instance, and can summon only player in our group with us as lead
254 if ( !m_session
->GetPlayer()->groupInfo
.group
|| !chr
->groupInfo
.group
||
255 (chr
->groupInfo
.group
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) ||
256 (m_session
->GetPlayer()->groupInfo
.group
->GetLeaderGUID() != m_session
->GetPlayer()->GetGUID()) )
257 // the last check is a bit excessive, but let it be, just in case
259 PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST
,chr
->GetName());
264 PSendSysMessage(LANG_SUMMONING
, chr
->GetName(),"");
266 if (m_session
->GetPlayer()->isVisibleFor(chr
))
269 snprintf((char*)buf0
,256,LANG_SUMMONED_BY
, m_session
->GetPlayer()->GetName());
272 FillSystemMessageData(&data
, m_session
, buf0
);
273 chr
->GetSession()->SendPacket( &data
);
276 chr
->SetRecallPosition(chr
->GetMapId(),chr
->GetPositionX(),chr
->GetPositionY(),chr
->GetPositionZ(),chr
->GetOrientation());
280 m_session
->GetPlayer()->GetClosePoint(NULL
,x
,y
,z
,chr
->GetObjectSize());
281 chr
->TeleportTo(m_session
->GetPlayer()->GetMapId(),x
,y
,z
,chr
->GetOrientation());
283 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
285 PSendSysMessage(LANG_SUMMONING
, name
.c_str()," (offline)");
287 // in point where GM stay
288 Player::SavePositionInDB(m_session
->GetPlayer()->GetMapId(),
289 m_session
->GetPlayer()->GetPositionX(),
290 m_session
->GetPlayer()->GetPositionY(),
291 m_session
->GetPlayer()->GetPositionZ(),m_session
->GetPlayer()->GetOrientation(),guid
);
294 PSendSysMessage(LANG_NO_PLAYER
, args
);
299 bool ChatHandler::HandleGonameCommand(const char* args
)
301 Player
* _player
= m_session
->GetPlayer();
303 if(_player
->isInFlight())
305 SendSysMessage(LANG_YOU_IN_FLIGHT
);
312 std::string name
= args
;
313 normalizePlayerName(name
);
314 //sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
316 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
319 if (MapManager::Instance().GetMap(chr
->GetMapId(), chr
)->Instanceable())
321 if ( (MapManager::Instance().GetMap(_player
->GetMapId(), _player
)->Instanceable()) &&
322 (MapManager::Instance().GetMap(chr
->GetMapId(), chr
)->GetInstanceId() !=
323 MapManager::Instance().GetMap(_player
->GetMapId(), _player
)->GetInstanceId()) )
325 // cannot go from instance to instance
326 PSendSysMessage(LANG_CANNOT_INST_INST
);
330 // we have to go to instance, and can go to player only if:
331 // 1) we are in his group (either as leader or as member)
332 // 2) we are not bound to any group and have GM mode on
333 if (_player
->groupInfo
.group
)
335 // we are in group, we can go only if we are in the player group
336 if (_player
->groupInfo
.group
!= chr
->groupInfo
.group
)
338 PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY
,chr
->GetName());
344 // we are not in group, let's verify our GM mode
345 if (!_player
->isGameMaster())
347 PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM
,chr
->GetName());
352 // bind us to the players instance
353 BoundInstancesMap::iterator i
= chr
->m_BoundInstances
.find(chr
->GetMapId());
354 if (i
== chr
->m_BoundInstances
.end()) return true; // error, the player has no instance bound!!!
355 _player
->m_BoundInstances
[chr
->GetMapId()] = std::pair
< uint32
, uint32
>(i
->second
.first
, i
->second
.second
);
356 _player
->SetInstanceId(chr
->GetInstanceId());
359 PSendSysMessage(LANG_APPEARING_AT
, chr
->GetName());
361 if (_player
->isVisibleFor(chr
))
364 sprintf((char*)buf0
,LANG_APPEARING_TO
, _player
->GetName());
367 FillSystemMessageData(&data
, m_session
, buf0
);
368 chr
->GetSession()->SendPacket(&data
);
371 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
373 // to point to see at target with same orientation
375 chr
->GetContactPoint(m_session
->GetPlayer(),x
,y
,z
);
377 _player
->TeleportTo(chr
->GetMapId(), x
, y
, z
, _player
->GetAngle( chr
), true, true, true);
381 if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
))
383 PSendSysMessage(LANG_APPEARING_AT
, name
.c_str());
385 // to point where player stay (if loaded)
388 if(Player::LoadPositionFromDB(map
,x
,y
,z
,o
,guid
))
390 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
391 _player
->TeleportTo(map
, x
, y
, z
,_player
->GetOrientation());
396 PSendSysMessage(LANG_NO_PLAYER
, args
);
401 bool ChatHandler::HandleRecallCommand(const char* args
)
407 chr
= getSelectedPlayer();
411 chr
= m_session
->GetPlayer();
413 if(chr
->isInFlight())
415 SendSysMessage(LANG_YOU_IN_FLIGHT
);
422 std::string name
= args
;
423 normalizePlayerName(name
);
424 //sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
426 chr
= objmgr
.GetPlayer(name
.c_str());
430 PSendSysMessage(LANG_NO_PLAYER
, args
);
435 if(chr
->IsBeingTeleported())
437 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
441 if(chr
->isInFlight())
443 PSendSysMessage(LANG_CHAR_IN_FLIGHT
, chr
->GetName());
447 chr
->TeleportTo(chr
->m_recallMap
, chr
->m_recallX
, chr
->m_recallY
, chr
->m_recallZ
, chr
->m_recallO
);
451 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args
)
453 uint32 titles
= atoi((char*)args
);
455 Player
*chr
= getSelectedPlayer();
458 SendSysMessage(LANG_NO_CHAR_SELECTED
);
462 chr
->SetUInt32Value(PLAYER_FIELD_KNOWN_TITLES
, titles
);
463 SendSysMessage(LANG_DONE
);
468 bool ChatHandler::HandleModifyHPCommand(const char* args
)
470 // char* pHp = strtok((char*)args, " ");
474 // char* pHpMax = strtok(NULL, " ");
478 // int32 hpm = atoi(pHpMax);
479 // int32 hp = atoi(pHp);
481 int32 hp
= atoi((char*)args
);
482 int32 hpm
= atoi((char*)args
);
484 if (hp
<= 0 || hpm
<= 0 || hpm
< hp
)
486 SendSysMessage(LANG_BAD_VALUE
);
490 Player
*chr
= getSelectedPlayer();
493 SendSysMessage(LANG_NO_CHAR_SELECTED
);
497 PSendSysMessage(LANG_YOU_CHANGE_HP
, hp
, hpm
, chr
->GetName());
501 sprintf((char*)buf
,LANG_YOURS_HP_CHANGED
, m_session
->GetPlayer()->GetName(), hp
, hpm
);
502 FillSystemMessageData(&data
, m_session
, buf
);
504 chr
->GetSession()->SendPacket(&data
);
506 chr
->SetMaxHealth( hpm
);
507 chr
->SetHealth( hp
);
512 bool ChatHandler::HandleModifyManaCommand(const char* args
)
514 // char* pmana = strtok((char*)args, " ");
518 // char* pmanaMax = strtok(NULL, " ");
522 // int32 manam = atoi(pmanaMax);
523 // int32 mana = atoi(pmana);
524 int32 mana
= atoi((char*)args
);
525 int32 manam
= atoi((char*)args
);
527 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
529 SendSysMessage(LANG_BAD_VALUE
);
533 Player
*chr
= getSelectedPlayer();
536 SendSysMessage(LANG_NO_CHAR_SELECTED
);
540 PSendSysMessage(LANG_YOU_CHANGE_MANA
, mana
, manam
, chr
->GetName());
544 sprintf((char*)buf
,LANG_YOURS_MANA_CHANGED
, m_session
->GetPlayer()->GetName(), mana
, manam
);
545 FillSystemMessageData(&data
, m_session
, buf
);
547 chr
->GetSession()->SendPacket(&data
);
549 chr
->SetMaxPower(POWER_MANA
,manam
);
550 chr
->SetPower(POWER_MANA
, mana
);
555 bool ChatHandler::HandleModifyEnergyCommand(const char* args
)
557 // char* pmana = strtok((char*)args, " ");
561 // char* pmanaMax = strtok(NULL, " ");
565 // int32 manam = atoi(pmanaMax);
566 // int32 mana = atoi(pmana);
567 int32 mana
= atoi((char*)args
)*10;
568 int32 manam
= atoi((char*)args
)*10;
570 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
572 SendSysMessage(LANG_BAD_VALUE
);
576 Player
*chr
= getSelectedPlayer();
579 PSendSysMessage(LANG_NO_CHAR_SELECTED
);
583 PSendSysMessage(LANG_YOU_CHANGE_ENERGY
, mana
/10, manam
/10, chr
->GetName());
587 sprintf((char*)buf
,LANG_YOURS_ENERGY_CHANGED
, m_session
->GetPlayer()->GetName(), mana
/10, manam
/10);
588 FillSystemMessageData(&data
, m_session
, buf
);
589 chr
->GetSession()->SendPacket(&data
);
591 chr
->SetMaxPower(POWER_ENERGY
,manam
);
592 chr
->SetPower(POWER_ENERGY
, mana
);
594 sLog
.outDetail(LANG_CURRENT_ENERGY
,chr
->GetMaxPower(POWER_ENERGY
));
599 bool ChatHandler::HandleModifyRageCommand(const char* args
)
601 // char* pmana = strtok((char*)args, " ");
605 // char* pmanaMax = strtok(NULL, " ");
609 // int32 manam = atoi(pmanaMax);
610 // int32 mana = atoi(pmana);
611 int32 mana
= atoi((char*)args
)*10;
612 int32 manam
= atoi((char*)args
)*10;
614 if (mana
<= 0 || manam
<= 0 || manam
< mana
)
616 SendSysMessage(LANG_BAD_VALUE
);
620 Player
*chr
= getSelectedPlayer();
623 SendSysMessage(LANG_NO_CHAR_SELECTED
);
627 PSendSysMessage(LANG_YOU_CHANGE_RAGE
, mana
/10, manam
/10, chr
->GetName());
631 sprintf((char*)buf
,LANG_YOURS_RAGE_CHANGED
, m_session
->GetPlayer()->GetName(), mana
/10, manam
/10);
632 FillSystemMessageData(&data
, m_session
, buf
);
634 chr
->GetSession()->SendPacket(&data
);
636 chr
->SetMaxPower(POWER_RAGE
,manam
);
637 chr
->SetPower(POWER_RAGE
, mana
);
642 bool ChatHandler::HandleModifyFactionCommand(const char* args
)
649 char* pfactionid
= strtok((char*)args
, " ");
651 Creature
* chr
= getSelectedCreature();
654 SendSysMessage(LANG_SELECT_CREATURE
);
662 factionid
= chr
->getFaction();
663 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
664 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
665 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
666 PSendSysMessage(LANG_CURRENT_FACTION
,chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
673 SendSysMessage(LANG_NO_CHAR_SELECTED
);
677 factionid
= atoi(pfactionid
);
679 char *pflag
= strtok(NULL
, " ");
681 flag
= chr
->GetUInt32Value(UNIT_FIELD_FLAGS
);
685 char* pnpcflag
= strtok(NULL
, " ");
687 npcflag
= chr
->GetUInt32Value(UNIT_NPC_FLAGS
);
689 npcflag
= atoi(pnpcflag
);
691 char* pdyflag
= strtok(NULL
, " ");
693 dyflag
= chr
->GetUInt32Value(UNIT_DYNAMIC_FLAGS
);
695 dyflag
= atoi(pdyflag
);
697 if(!sFactionTemplateStore
.LookupEntry(factionid
))
699 PSendSysMessage(LANG_WRONG_FACTION
, factionid
);
703 PSendSysMessage(LANG_YOU_CHANGE_FACTION
, chr
->GetGUIDLow(),factionid
,flag
,npcflag
,dyflag
);
705 //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
706 //FillSystemMessageData(&data, m_session, buf);
708 //chr->GetSession()->SendPacket(&data);
710 chr
->setFaction(factionid
);
711 chr
->SetUInt32Value(UNIT_FIELD_FLAGS
,flag
);
712 chr
->SetUInt32Value(UNIT_NPC_FLAGS
,npcflag
);
713 chr
->SetUInt32Value(UNIT_DYNAMIC_FLAGS
,dyflag
);
718 bool ChatHandler::HandleModifySpellCommand(const char* args
)
720 char* pspellflatid
= strtok((char*)args
, " ");
724 char* pop
= strtok(NULL
, " ");
728 char* pval
= strtok(NULL
, " ");
734 char* pmark
= strtok(NULL
, " ");
736 uint8 spellflatid
= atoi(pspellflatid
);
737 uint8 op
= atoi(pop
);
738 uint16 val
= atoi(pval
);
744 Player
*chr
= getSelectedPlayer();
747 SendSysMessage(LANG_NO_CHAR_SELECTED
);
751 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID
, spellflatid
, val
, mark
, chr
->GetName());
755 sprintf((char*)buf
,LANG_YOURS_SPELLFLATID_CHANGED
, m_session
->GetPlayer()->GetName(), spellflatid
, val
, mark
);
756 FillSystemMessageData(&data
, m_session
, buf
);
758 chr
->GetSession()->SendPacket(&data
);
760 data
.Initialize(SMSG_SET_FLAT_SPELL_MODIFIER
, (1+1+2+2));
761 data
<< uint8(spellflatid
);
764 data
<< uint16(mark
);
765 chr
->GetSession()->SendPacket(&data
);
770 bool ChatHandler::HandleModifyTalentCommand (const char* args
)
775 int tp
= atoi((char*)args
);
778 Player
* player
= getSelectedPlayer();
781 SendSysMessage(LANG_NO_CHAR_SELECTED
);
784 player
->SetFreeTalentPoints(tp
);
790 bool ChatHandler::HandleTaxiCheatCommand(const char* args
)
795 int flag
= atoi((char*)args
);
797 Player
*chr
= getSelectedPlayer();
800 SendSysMessage(LANG_NO_CHAR_SELECTED
);
806 chr
->SetTaxiCheater(true);
807 PSendSysMessage(LANG_YOU_GIVE_TAXIS
, chr
->GetName());
809 if(chr
!= m_session
->GetPlayer())
813 sprintf((char*)buf
,LANG_YOURS_TAXIS_ADDED
, m_session
->GetPlayer()->GetName());
814 FillSystemMessageData(&data
, m_session
, buf
);
815 chr
->GetSession()->SendPacket(&data
);
820 chr
->SetTaxiCheater(false);
821 PSendSysMessage(LANG_YOU_REMOVE_TAXIS
, chr
->GetName());
823 if(chr
!= m_session
->GetPlayer())
827 sprintf((char*)buf
,LANG_YOURS_TAXIS_REMOVED
, m_session
->GetPlayer()->GetName());
828 FillSystemMessageData(&data
, m_session
, buf
);
829 chr
->GetSession()->SendPacket(&data
);
836 bool ChatHandler::HandleModifyASpeedCommand(const char* args
)
841 float ASpeed
= (float)atof((char*)args
);
843 if (ASpeed
> 10 || ASpeed
< 0.1)
845 SendSysMessage(LANG_BAD_VALUE
);
849 Player
*chr
= getSelectedPlayer();
852 SendSysMessage(LANG_NO_CHAR_SELECTED
);
856 if(chr
->isInFlight())
858 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
862 PSendSysMessage(LANG_YOU_CHANGE_ASPEED
, ASpeed
, chr
->GetName());
866 sprintf((char*)buf
,LANG_YOURS_ASPEED_CHANGED
, m_session
->GetPlayer()->GetName(), ASpeed
);
867 FillSystemMessageData(&data
, m_session
, buf
);
869 chr
->GetSession()->SendPacket(&data
);
871 chr
->SetSpeed(MOVE_WALK
, ASpeed
,true);
872 chr
->SetSpeed(MOVE_RUN
, ASpeed
,true);
873 chr
->SetSpeed(MOVE_WALKBACK
,ASpeed
,true);
874 chr
->SetSpeed(MOVE_SWIM
, ASpeed
,true);
875 chr
->SetSpeed(MOVE_SWIMBACK
,ASpeed
,true);
876 //chr->SetSpeed(MOVE_TURN, ASpeed,true);
877 chr
->SetSpeed(MOVE_FLY
, ASpeed
,true);
881 bool ChatHandler::HandleModifySpeedCommand(const char* args
)
886 float Speed
= (float)atof((char*)args
);
888 if (Speed
> 10 || Speed
< 0.1)
890 SendSysMessage(LANG_BAD_VALUE
);
894 Player
*chr
= getSelectedPlayer();
897 SendSysMessage(LANG_NO_CHAR_SELECTED
);
901 if(chr
->isInFlight())
903 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
907 PSendSysMessage(LANG_YOU_CHANGE_SPEED
, Speed
, chr
->GetName());
911 sprintf((char*)buf
,LANG_YOURS_SPEED_CHANGED
, m_session
->GetPlayer()->GetName(), Speed
);
912 FillSystemMessageData(&data
, m_session
, buf
);
914 chr
->GetSession()->SendPacket(&data
);
916 chr
->SetSpeed(MOVE_RUN
,Speed
,true);
921 bool ChatHandler::HandleModifySwimCommand(const char* args
)
926 float Swim
= (float)atof((char*)args
);
928 if (Swim
> 10 || Swim
< 0.01)
930 SendSysMessage(LANG_BAD_VALUE
);
934 Player
*chr
= getSelectedPlayer();
937 SendSysMessage(LANG_NO_CHAR_SELECTED
);
941 if(chr
->isInFlight())
943 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
947 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED
, Swim
, chr
->GetName());
951 sprintf((char*)buf
,LANG_YOURS_SWIM_SPEED_CHANGED
, m_session
->GetPlayer()->GetName(), Swim
);
952 FillSystemMessageData(&data
, m_session
, buf
);
954 chr
->GetSession()->SendPacket(&data
);
956 chr
->SetSpeed(MOVE_SWIM
,Swim
,true);
961 bool ChatHandler::HandleModifyBWalkCommand(const char* args
)
966 float BSpeed
= (float)atof((char*)args
);
968 if (BSpeed
> 10 || BSpeed
< 0.1)
970 SendSysMessage(LANG_BAD_VALUE
);
974 Player
*chr
= getSelectedPlayer();
977 SendSysMessage(LANG_NO_CHAR_SELECTED
);
981 if(chr
->isInFlight())
983 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
987 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED
, BSpeed
, chr
->GetName());
991 sprintf((char*)buf
,LANG_YOURS_BACK_SPEED_CHANGED
, m_session
->GetPlayer()->GetName(), BSpeed
);
992 FillSystemMessageData(&data
, m_session
, buf
);
994 chr
->GetSession()->SendPacket(&data
);
996 chr
->SetSpeed(MOVE_WALKBACK
,BSpeed
,true);
1001 bool ChatHandler::HandleModifyFlyCommand(const char* args
)
1006 float FSpeed
= (float)atof((char*)args
);
1008 if (FSpeed
> 10 || FSpeed
< 0.1)
1010 SendSysMessage(LANG_BAD_VALUE
);
1014 Player
*chr
= getSelectedPlayer();
1017 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1021 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED
, FSpeed
, chr
->GetName());
1025 sprintf((char*)buf
,LANG_YOURS_FLY_SPEED_CHANGED
, m_session
->GetPlayer()->GetName(), FSpeed
);
1026 FillSystemMessageData(&data
, m_session
, buf
);
1028 chr
->GetSession()->SendPacket(&data
);
1030 chr
->SetSpeed(MOVE_FLY
,FSpeed
,true);
1035 bool ChatHandler::HandleModifyScaleCommand(const char* args
)
1040 float Scale
= (float)atof((char*)args
);
1041 if (Scale
> 3 || Scale
<= 0)
1043 SendSysMessage(LANG_BAD_VALUE
);
1047 Player
*chr
= getSelectedPlayer();
1050 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1054 PSendSysMessage(LANG_YOU_CHANGE_SIZE
, Scale
, chr
->GetName());
1058 sprintf((char*)buf
,LANG_YOURS_SIZE_CHANGED
, m_session
->GetPlayer()->GetName(), Scale
);
1059 FillSystemMessageData(&data
, m_session
, buf
);
1061 chr
->GetSession()->SendPacket(&data
);
1063 chr
->SetFloatValue(OBJECT_FIELD_SCALE_X
, Scale
);
1068 bool ChatHandler::HandleModifyMountCommand(const char* args
)
1074 float speed
= (float)15;
1077 num
= atoi((char*)args
);
1288 SendSysMessage(LANG_NO_MOUNT
);
1292 Player
*chr
= getSelectedPlayer();
1295 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1299 PSendSysMessage(LANG_YOU_GIVE_MOUNT
, chr
->GetName());
1303 sprintf((char*)buf
,LANG_MOUNT_GIVED
, m_session
->GetPlayer()->GetName());
1304 FillSystemMessageData(&data
, m_session
, buf
);
1306 chr
->GetSession()->SendPacket(&data
);
1308 chr
->SetUInt32Value( UNIT_FIELD_FLAGS
, 0x001000 );
1311 data
.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE
, (8+4+4) );
1312 data
.append(chr
->GetPackGUID());
1314 data
<< float(speed
);
1315 chr
->SendMessageToSet( &data
, true );
1317 data
.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE
, (8+4+4) );
1318 data
.append(chr
->GetPackGUID());
1320 data
<< float(speed
);
1321 chr
->SendMessageToSet( &data
, true );
1326 bool ChatHandler::HandleModifyMoneyCommand(const char* args
)
1331 Player
*chr
= getSelectedPlayer();
1334 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1338 int32 addmoney
= atoi((char*)args
);
1340 uint32 moneyuser
= m_session
->GetPlayer()->GetMoney();
1344 int32 newmoney
= moneyuser
+ addmoney
;
1346 sLog
.outDetail(LANG_CURRENT_MONEY
, moneyuser
, addmoney
, newmoney
);
1349 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY
, chr
->GetName());
1353 sprintf((char*)buf
,LANG_YOURS_ALL_MONEY_GONE
, m_session
->GetPlayer()->GetName());
1354 FillSystemMessageData(&data
, m_session
, buf
);
1355 chr
->GetSession()->SendPacket(&data
);
1361 PSendSysMessage(LANG_YOU_TAKE_MONEY
, abs(addmoney
), chr
->GetName());
1365 sprintf((char*)buf
,LANG_YOURS_MONEY_TAKEN
, m_session
->GetPlayer()->GetName(), abs(addmoney
));
1366 FillSystemMessageData(&data
, m_session
, buf
);
1367 chr
->GetSession()->SendPacket(&data
);
1369 chr
->SetMoney( newmoney
);
1374 PSendSysMessage(LANG_YOU_GIVE_MONEY
, addmoney
, chr
->GetName());
1378 sprintf((char*)buf
,LANG_YOURS_MONEY_GIVEN
, m_session
->GetPlayer()->GetName(), addmoney
);
1379 FillSystemMessageData(&data
, m_session
, buf
);
1380 chr
->GetSession()->SendPacket(&data
);
1382 chr
->ModifyMoney( addmoney
);
1385 sLog
.outDetail(LANG_NEW_MONEY
, moneyuser
, addmoney
, chr
->GetMoney() );
1390 bool ChatHandler::HandleModifyBitCommand(const char* args
)
1395 Player
*chr
= getSelectedPlayer();
1398 SendSysMessage(LANG_NO_CHAR_SELECTED
);
1402 char* pField
= strtok((char*)args
, " ");
1406 char* pBit
= strtok(NULL
, " ");
1410 uint16 field
= atoi(pField
);
1411 uint32 bit
= atoi(pBit
);
1413 if (field
< 1 || field
>= PLAYER_END
)
1415 SendSysMessage(LANG_BAD_VALUE
);
1419 if (bit
< 1 || bit
> 32)
1421 SendSysMessage(LANG_BAD_VALUE
);
1425 if ( chr
->HasFlag( field
, (1<<(bit
-1)) ) )
1427 chr
->RemoveFlag( field
, (1<<(bit
-1)) );
1428 PSendSysMessage(LANG_REMOVE_BIT
, bit
, field
);
1432 chr
->SetFlag( field
, (1<<(bit
-1)) );
1433 PSendSysMessage(LANG_SET_BIT
, bit
, field
);
1439 bool ChatHandler::HandleTeleCommand(const char * args
)
1441 Player
* _player
= m_session
->GetPlayer();
1443 if(_player
->isInFlight())
1445 SendSysMessage(LANG_YOU_IN_FLIGHT
);
1449 char* cId
= extractKeyFromLink((char*)args
,"Htele"); // string or [name] Shift-click form |color|Htele:name|h[name]|h|r
1453 std::string name
= cId
;
1454 sDatabase
.escape_string(name
);
1456 QueryResult
*result
= sDatabase
.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `game_tele` WHERE `name` = '%s'",name
.c_str());
1459 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1462 Field
*fields
= result
->Fetch();
1463 float x
= fields
[0].GetFloat();
1464 float y
= fields
[1].GetFloat();
1465 float z
= fields
[2].GetFloat();
1466 float ort
= fields
[3].GetFloat();
1467 int mapid
= fields
[4].GetUInt16();
1470 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
1472 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
1476 _player
->SetRecallPosition(_player
->GetMapId(),_player
->GetPositionX(),_player
->GetPositionY(),_player
->GetPositionZ(),_player
->GetOrientation());
1478 _player
->TeleportTo(mapid
, x
, y
, z
, ort
);
1482 bool ChatHandler::HandleLookupTeleCommand(const char * args
)
1484 QueryResult
*result
;
1487 SendSysMessage(LANG_COMMAND_TELE_PARAMETER
);
1490 char const* str
= strtok((char*)args
, " ");
1494 std::string namepart
= str
;
1495 sDatabase
.escape_string(namepart
);
1496 result
= sDatabase
.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",namepart
.c_str());
1499 SendSysMessage(LANG_COMMAND_TELE_NOREQUEST
);
1503 for (uint64 i
=0; i
< result
->GetRowCount(); i
++)
1505 Field
*fields
= result
->Fetch();
1506 reply
+= " |cffffffff|Htele:";
1507 reply
+= fields
[0].GetCppString();
1509 reply
+= fields
[0].GetCppString();
1516 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION
);
1519 reply
= LANG_COMMAND_TELE_LOCATION
+ reply
;
1520 SendSysMultilineMessage(reply
.c_str());
1525 bool ChatHandler::HandleWhispersCommand(const char* args
)
1527 char* px
= strtok((char*)args
, " ");
1532 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING
, m_session
->GetPlayer()->isAcceptWhispers() ? LANG_ON
: LANG_OFF
);
1537 if(strncmp(px
,"on",3) == 0)
1539 m_session
->GetPlayer()->SetAcceptWhispers(true);
1540 SendSysMessage(LANG_COMMAND_WHISPERON
);
1545 if(strncmp(px
,"off",4) == 0)
1547 m_session
->GetPlayer()->SetAcceptWhispers(false);
1548 SendSysMessage(LANG_COMMAND_WHISPEROFF
);
1555 bool ChatHandler::HandlePlaySoundCommand(const char* args
)
1557 // USAGE: .playsound #soundid
1558 // #soundid - ID decimal number from SoundEntries.dbc (1 column)
1559 // this file have about 5000 sounds.
1560 // In this realisation only caller can hear this sound.
1563 int dwSoundId
= atoi((char*)args
);
1564 if( dwSoundId
>= 0 )
1566 WorldPacket
data(SMSG_PLAY_OBJECT_SOUND
,4+8);
1567 data
<< uint32(dwSoundId
) << m_session
->GetPlayer()->GetGUID();
1568 m_session
->SendPacket(&data
);
1570 sLog
.outDebug("Player %s use command .playsound with #soundid=%u", m_session
->GetPlayer()->GetName(), dwSoundId
);
1571 PSendSysMessage(LANG_YOU_HEAR_SOUND
, dwSoundId
);
1576 SendSysMessage(LANG_BAD_VALUE
);
1580 bool ChatHandler::HandleSaveAllCommand(const char* args
)
1582 ObjectAccessor::Instance().SaveAllPlayers();
1583 SendSysMessage(LANG_PLAYERS_SAVED
);
1587 bool ChatHandler::HandleSendMailCommand(const char* args
)
1592 char* pName
= strtok((char*)args
, " ");
1593 char* msgSubject
= strtok(NULL
, " ");
1594 char* msgText
= strtok(NULL
, "");
1599 // pName, msgSubject, msgText isn't NUL after prev. check
1601 std::string name
= pName
;
1602 std::string subject
= msgSubject
;
1603 std::string text
= msgText
;
1605 normalizePlayerName(name
);
1607 uint32 receiver_guid
= objmgr
.GetPlayerGUIDByName(name
);
1608 uint32 mailId
= objmgr
.GenerateMailID();
1609 uint32 sender_guid
= m_session
->GetPlayer()->GetGUID();
1610 time_t dtime
= time(NULL
);
1611 time_t etime
= dtime
+ (30 * DAY
);
1612 uint32 messagetype
= MAIL_GM
;
1613 uint32 itemTextId
= 0;
1614 if (text
.size() > 0)
1616 itemTextId
= objmgr
.CreateItemText( text
);
1619 Player
*receiver
= objmgr
.GetPlayer((uint32
) receiver_guid
);
1621 receiver
->CreateMail(mailId
,messagetype
,sender_guid
,subject
.c_str(),itemTextId
,0,0,(uint64
)etime
,(uint64
)dtime
,0,0,0,0);
1623 sDatabase
.escape_string(subject
);
1624 sDatabase
.PExecute("INSERT INTO `mail` (`id`,`messageType`,`sender`,`receiver`,`subject`,`itemTextId`,`item_guid`,`item_template`,`expire_time`,`deliver_time`,`money`,`cod`,`checked`) "
1625 "VALUES ('%u', '%u', '%u', '%u', '%s', '%u', '0', '0', '" I64FMTD
"','" I64FMTD
"', '0', '0', '%d')",
1626 mailId
, messagetype
, sender_guid
, receiver_guid
, subject
.c_str(), itemTextId
, (uint64
)etime
, (uint64
)dtime
, NOT_READ
);
1628 PSendSysMessage(LANG_MAIL_SENT
, name
.c_str());
1632 bool ChatHandler::HandleNameTeleCommand(const char * args
)
1634 char* pName
= strtok((char*)args
, " ");
1635 char* loc
= strtok(NULL
, "");
1640 std::string name
= pName
;
1641 std::string location
= loc
;
1643 normalizePlayerName(name
);
1644 sDatabase
.escape_string(name
);
1646 QueryResult
*result
= sDatabase
.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `game_tele` WHERE `name` = '%s'",location
.c_str());
1649 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND
);
1653 Field
*fields
= result
->Fetch();
1654 float x
= fields
[0].GetFloat();
1655 float y
= fields
[1].GetFloat();
1656 float z
= fields
[2].GetFloat();
1657 float ort
= fields
[3].GetFloat();
1658 int mapid
= fields
[4].GetUInt16();
1661 if(!MapManager::IsValidMapCoord(mapid
,x
,y
))
1663 PSendSysMessage(LANG_INVALID_TARGET_COORD
,x
,y
,mapid
);
1667 Player
*chr
= objmgr
.GetPlayer(name
.c_str());
1671 if(chr
->IsBeingTeleported()==true)
1673 PSendSysMessage(LANG_IS_TELEPORTED
, chr
->GetName());
1677 if(chr
->isInFlight())
1679 PSendSysMessage(LANG_CHAR_IN_FLIGHT
,chr
->GetName());
1683 PSendSysMessage(LANG_TELEPORTING_TO
, chr
->GetName(),"", location
.c_str());
1685 if (m_session
->GetPlayer()->isVisibleFor(chr
))
1689 snprintf((char*)buf0
,256,LANG_TELEPORTED_TO_BY
, m_session
->GetPlayer()->GetName());
1690 FillSystemMessageData(&data
, m_session
, buf0
);
1691 chr
->GetSession()->SendPacket( &data
);
1694 chr
->SetRecallPosition(chr
->GetMapId(),chr
->GetPositionX(),chr
->GetPositionY(),chr
->GetPositionZ(),chr
->GetOrientation());
1696 chr
->TeleportTo(mapid
,x
,y
,z
,chr
->GetOrientation());
1698 else if (uint64 guid
= objmgr
.GetPlayerGUIDByName(name
.c_str()))
1700 PSendSysMessage(LANG_TELEPORTING_TO
, name
.c_str(), LANG_OFFLINE
, location
.c_str());
1701 Player::SavePositionInDB(mapid
,x
,y
,z
,ort
,guid
);
1704 PSendSysMessage(LANG_NO_PLAYER
, name
.c_str());