[4054] added: Line of sight (vmaps) [part 1]
[mangos-git.git] / src / game / Level1.cpp
blob0403333819479809788bc09e78e46a20ffed33ea
1 /*
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
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 "RedZoneDistrict.h"
33 #include "Transports.h"
34 #ifdef _DEBUG_VMAPS
35 #include "VMapFactory.h"
36 #endif
37 bool ChatHandler::HandleSayCommand(const char* args)
39 uint64 guid = m_session->GetPlayer()->GetSelection();
40 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
42 if(!pCreature)
44 SendSysMessage(LANG_SELECT_CREATURE);
45 return true;
48 pCreature->Say(args, LANG_UNIVERSAL, 0);
50 return true;
53 bool ChatHandler::HandleYellCommand(const char* args)
55 uint64 guid = m_session->GetPlayer()->GetSelection();
56 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
58 if(!pCreature)
60 SendSysMessage(LANG_SELECT_CREATURE);
61 return true;
64 pCreature->Yell(args, LANG_UNIVERSAL, 0);
66 return true;
69 bool ChatHandler::HandleEmote2Command(const char* args)
71 uint64 guid = m_session->GetPlayer()->GetSelection();
72 Creature* pCreature = ObjectAccessor::Instance().GetCreature(*m_session->GetPlayer(), guid);
74 if(!pCreature)
76 SendSysMessage(LANG_SELECT_CREATURE);
77 return true;
80 pCreature->TextEmote(args, 0);
82 return true;
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);
96 return true;
99 pCreature->Whisper(atol(receiver), text);
101 return true;
104 bool ChatHandler::HandleAnnounceCommand(const char* args)
106 if(!*args)
107 return false;
109 std::string str = LANG_SYSTEMMESSAGE;
110 str += args;
111 sWorld.SendWorldText(str.c_str(), NULL);
113 #ifdef _DEBUG_VMAPS
114 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
115 float x,y,z;
116 m_session->GetPlayer()->GetPosition(x,y,z);
117 char buffer[100];
118 sprintf(buffer, "pos %f,%f,%f",x,y,z);
119 vMapManager->processCommand(buffer);
120 #endif
121 return true;
124 bool ChatHandler::HandleNotifyCommand(const char* args)
126 if(!*args)
127 return false;
129 std::string str = LANG_GLOBAL_NOTIFY;
130 str += args;
132 WorldPacket data(SMSG_NOTIFICATION, (str.size()+1));
133 data << str;
134 sWorld.SendGlobalMessage(&data);
136 return true;
139 bool ChatHandler::HandleGMOnCommand(const char* args)
141 m_session->GetPlayer()->SetGameMaster(true);
142 m_session->SendNotification("GM mode is ON");
143 #ifdef _DEBUG_VMAPS
144 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
145 vMapManager->processCommand("stoplog");
146 #endif
147 return true;
150 bool ChatHandler::HandleGMOffCommand(const char* args)
152 m_session->GetPlayer()->SetGameMaster(false);
153 m_session->SendNotification("GM mode is OFF");
154 #ifdef _DEBUG_VMAPS
155 VMAP::IVMapManager *vMapManager = VMAP::VMapFactory::createOrGetVMapManager();
156 vMapManager->processCommand("startlog");
157 #endif
158 return true;
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);
169 return true;
172 if ( option )
174 m_session->GetPlayer()->SetGMVisible(true);
175 m_session->SendNotification( LANG_INVISIBLE_VISIBLE );
177 else
179 m_session->SendNotification( LANG_INVISIBLE_INVISIBLE );
180 m_session->GetPlayer()->SetGMVisible(false);
183 return true;
186 bool ChatHandler::HandleGPSCommand(const char* args)
188 WorldObject *obj = getSelectedUnit();
190 if(!obj)
192 SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
193 return true;
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());
208 return true;
211 bool ChatHandler::HandleNamegoCommand(const char* args)
213 if(m_session->GetPlayer()->isInFlight())
215 SendSysMessage(LANG_YOU_IN_FLIGHT);
216 return true;
219 if(!*args)
220 return false;
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());
227 if (chr)
230 if(chr->IsBeingTeleported()==true)
232 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
233 return true;
236 if(chr->isInFlight())
238 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
239 return true;
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);
250 return true;
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());
260 return true;
264 PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
266 if (m_session->GetPlayer()->isVisibleFor(chr))
268 char buf0[256];
269 snprintf((char*)buf0,256,LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
271 WorldPacket data;
272 FillSystemMessageData(&data, m_session, buf0);
273 chr->GetSession()->SendPacket( &data );
276 chr->SetRecallPosition(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation());
278 // before GM
279 float x,y,z;
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);
293 else
294 PSendSysMessage(LANG_NO_PLAYER, args);
296 return true;
299 bool ChatHandler::HandleGonameCommand(const char* args)
301 Player* _player = m_session->GetPlayer();
303 if(_player->isInFlight())
305 SendSysMessage(LANG_YOU_IN_FLIGHT);
306 return true;
309 if(!*args)
310 return false;
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());
317 if (chr)
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);
327 return true;
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());
339 return true;
342 else
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());
348 return true;
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))
363 char buf0[256];
364 sprintf((char*)buf0,LANG_APPEARING_TO, _player->GetName());
366 WorldPacket data;
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
374 float x,y,z;
375 chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
377 _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), true, true, true);
378 return true;
381 if (uint64 guid = objmgr.GetPlayerGUIDByName(name))
383 PSendSysMessage(LANG_APPEARING_AT, name.c_str());
385 // to point where player stay (if loaded)
386 float x,y,z,o;
387 uint32 map;
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());
392 return true;
396 PSendSysMessage(LANG_NO_PLAYER, args);
398 return true;
401 bool ChatHandler::HandleRecallCommand(const char* args)
403 Player* chr = NULL;
405 if(!*args)
407 chr = getSelectedPlayer();
409 if(!chr)
411 chr = m_session->GetPlayer();
413 if(chr->isInFlight())
415 SendSysMessage(LANG_YOU_IN_FLIGHT);
416 return true;
420 else
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());
428 if(!chr)
430 PSendSysMessage(LANG_NO_PLAYER, args);
431 return true;
435 if(chr->IsBeingTeleported())
437 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
438 return true;
441 if(chr->isInFlight())
443 PSendSysMessage(LANG_CHAR_IN_FLIGHT, chr->GetName());
444 return true;
447 chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
448 return true;
451 bool ChatHandler::HandleModifyKnownTitlesCommand(const char* args)
453 uint32 titles = atoi((char*)args);
455 Player *chr = getSelectedPlayer();
456 if (chr == NULL)
458 SendSysMessage(LANG_NO_CHAR_SELECTED);
459 return true;
462 chr->SetUInt32Value(PLAYER_FIELD_KNOWN_TITLES, titles);
463 SendSysMessage(LANG_DONE);
465 return true;
468 bool ChatHandler::HandleModifyHPCommand(const char* args)
470 // char* pHp = strtok((char*)args, " ");
471 // if (!pHp)
472 // return false;
474 // char* pHpMax = strtok(NULL, " ");
475 // if (!pHpMax)
476 // return false;
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);
487 return true;
490 Player *chr = getSelectedPlayer();
491 if (chr == NULL)
493 SendSysMessage(LANG_NO_CHAR_SELECTED);
494 return true;
497 PSendSysMessage(LANG_YOU_CHANGE_HP, hp, hpm, chr->GetName());
499 WorldPacket data;
500 char buf[256];
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 );
509 return true;
512 bool ChatHandler::HandleModifyManaCommand(const char* args)
514 // char* pmana = strtok((char*)args, " ");
515 // if (!pmana)
516 // return false;
518 // char* pmanaMax = strtok(NULL, " ");
519 // if (!pmanaMax)
520 // return false;
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);
530 return true;
533 Player *chr = getSelectedPlayer();
534 if (chr == NULL)
536 SendSysMessage(LANG_NO_CHAR_SELECTED);
537 return true;
540 PSendSysMessage(LANG_YOU_CHANGE_MANA, mana, manam, chr->GetName());
542 WorldPacket data;
543 char buf[256];
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 );
552 return true;
555 bool ChatHandler::HandleModifyEnergyCommand(const char* args)
557 // char* pmana = strtok((char*)args, " ");
558 // if (!pmana)
559 // return false;
561 // char* pmanaMax = strtok(NULL, " ");
562 // if (!pmanaMax)
563 // return false;
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);
573 return true;
576 Player *chr = getSelectedPlayer();
577 if (chr == NULL)
579 PSendSysMessage(LANG_NO_CHAR_SELECTED);
580 return true;
583 PSendSysMessage(LANG_YOU_CHANGE_ENERGY, mana/10, manam/10, chr->GetName());
585 WorldPacket data;
586 char buf[256];
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));
596 return true;
599 bool ChatHandler::HandleModifyRageCommand(const char* args)
601 // char* pmana = strtok((char*)args, " ");
602 // if (!pmana)
603 // return false;
605 // char* pmanaMax = strtok(NULL, " ");
606 // if (!pmanaMax)
607 // return false;
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);
617 return true;
620 Player *chr = getSelectedPlayer();
621 if (chr == NULL)
623 SendSysMessage(LANG_NO_CHAR_SELECTED);
624 return true;
627 PSendSysMessage(LANG_YOU_CHANGE_RAGE, mana/10, manam/10, chr->GetName());
629 WorldPacket data;
630 char buf[256];
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 );
639 return true;
642 bool ChatHandler::HandleModifyFactionCommand(const char* args)
644 uint32 factionid;
645 uint32 flag;
646 uint32 npcflag;
647 uint32 dyflag;
649 char* pfactionid = strtok((char*)args, " ");
651 Creature* chr = getSelectedCreature();
652 if(!chr)
654 SendSysMessage(LANG_SELECT_CREATURE);
655 return true;
658 if(!pfactionid)
660 if(chr)
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);
668 return true;
671 if (chr == NULL)
673 SendSysMessage(LANG_NO_CHAR_SELECTED);
674 return true;
677 factionid = atoi(pfactionid);
679 char *pflag = strtok(NULL, " ");
680 if (!pflag)
681 flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
682 else
683 flag = atoi(pflag);
685 char* pnpcflag = strtok(NULL, " ");
686 if(!pnpcflag)
687 npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
688 else
689 npcflag = atoi(pnpcflag);
691 char* pdyflag = strtok(NULL, " ");
692 if(!pdyflag)
693 dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
694 else
695 dyflag = atoi(pdyflag);
697 if(!sFactionTemplateStore.LookupEntry(factionid))
699 PSendSysMessage(LANG_WRONG_FACTION, factionid);
700 return true;
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);
715 return true;
718 bool ChatHandler::HandleModifySpellCommand(const char* args)
720 char* pspellflatid = strtok((char*)args, " ");
721 if (!pspellflatid)
722 return false;
724 char* pop = strtok(NULL, " ");
725 if (!pop)
726 return false;
728 char* pval = strtok(NULL, " ");
729 if (!pval)
730 return false;
732 uint16 mark;
734 char* pmark = strtok(NULL, " ");
736 uint8 spellflatid = atoi(pspellflatid);
737 uint8 op = atoi(pop);
738 uint16 val = atoi(pval);
739 if(!pmark)
740 mark = 65535;
741 else
742 mark = atoi(pmark);
744 Player *chr = getSelectedPlayer();
745 if (chr == NULL)
747 SendSysMessage(LANG_NO_CHAR_SELECTED);
748 return true;
751 PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
753 WorldPacket data;
754 char buf[256];
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);
762 data << uint8(op);
763 data << uint16(val);
764 data << uint16(mark);
765 chr->GetSession()->SendPacket(&data);
767 return true;
770 bool ChatHandler::HandleModifyTalentCommand (const char* args)
772 if (!*args)
773 return false;
775 int tp = atoi((char*)args);
776 if (tp>0)
778 Player* player = getSelectedPlayer();
779 if(!player)
781 SendSysMessage(LANG_NO_CHAR_SELECTED);
782 return true;
784 player->SetFreeTalentPoints(tp);
785 return true;
787 return false;
790 bool ChatHandler::HandleTaxiCheatCommand(const char* args)
792 if (!*args)
793 return false;
795 int flag = atoi((char*)args);
797 Player *chr = getSelectedPlayer();
798 if (chr == NULL)
800 SendSysMessage(LANG_NO_CHAR_SELECTED);
801 return true;
804 if (flag != 0)
806 chr->SetTaxiCheater(true);
807 PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
809 if(chr != m_session->GetPlayer())
811 WorldPacket data;
812 char buf[256];
813 sprintf((char*)buf,LANG_YOURS_TAXIS_ADDED, m_session->GetPlayer()->GetName());
814 FillSystemMessageData(&data, m_session, buf);
815 chr->GetSession()->SendPacket(&data);
818 else
820 chr->SetTaxiCheater(false);
821 PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
823 if(chr != m_session->GetPlayer())
825 WorldPacket data;
826 char buf[256];
827 sprintf((char*)buf,LANG_YOURS_TAXIS_REMOVED, m_session->GetPlayer()->GetName());
828 FillSystemMessageData(&data, m_session, buf);
829 chr->GetSession()->SendPacket(&data);
833 return true;
836 bool ChatHandler::HandleModifyASpeedCommand(const char* args)
838 if (!*args)
839 return false;
841 float ASpeed = (float)atof((char*)args);
843 if (ASpeed > 10 || ASpeed < 0.1)
845 SendSysMessage(LANG_BAD_VALUE);
846 return true;
849 Player *chr = getSelectedPlayer();
850 if (chr == NULL)
852 SendSysMessage(LANG_NO_CHAR_SELECTED);
853 return true;
856 if(chr->isInFlight())
858 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
859 return true;
862 PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed, chr->GetName());
864 WorldPacket data;
865 char buf[256];
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);
878 return true;
881 bool ChatHandler::HandleModifySpeedCommand(const char* args)
883 if (!*args)
884 return false;
886 float Speed = (float)atof((char*)args);
888 if (Speed > 10 || Speed < 0.1)
890 SendSysMessage(LANG_BAD_VALUE);
891 return true;
894 Player *chr = getSelectedPlayer();
895 if (chr == NULL)
897 SendSysMessage(LANG_NO_CHAR_SELECTED);
898 return true;
901 if(chr->isInFlight())
903 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
904 return true;
907 PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
909 WorldPacket data;
910 char buf[256];
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);
918 return true;
921 bool ChatHandler::HandleModifySwimCommand(const char* args)
923 if (!*args)
924 return false;
926 float Swim = (float)atof((char*)args);
928 if (Swim > 10 || Swim < 0.01)
930 SendSysMessage(LANG_BAD_VALUE);
931 return true;
934 Player *chr = getSelectedPlayer();
935 if (chr == NULL)
937 SendSysMessage(LANG_NO_CHAR_SELECTED);
938 return true;
941 if(chr->isInFlight())
943 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
944 return true;
947 PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
949 WorldPacket data;
950 char buf[256];
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);
958 return true;
961 bool ChatHandler::HandleModifyBWalkCommand(const char* args)
963 if (!*args)
964 return false;
966 float BSpeed = (float)atof((char*)args);
968 if (BSpeed > 10 || BSpeed < 0.1)
970 SendSysMessage(LANG_BAD_VALUE);
971 return true;
974 Player *chr = getSelectedPlayer();
975 if (chr == NULL)
977 SendSysMessage(LANG_NO_CHAR_SELECTED);
978 return true;
981 if(chr->isInFlight())
983 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
984 return true;
987 PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
989 WorldPacket data;
990 char buf[256];
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);
998 return true;
1001 bool ChatHandler::HandleModifyFlyCommand(const char* args)
1003 if (!*args)
1004 return false;
1006 float FSpeed = (float)atof((char*)args);
1008 if (FSpeed > 10 || FSpeed < 0.1)
1010 SendSysMessage(LANG_BAD_VALUE);
1011 return true;
1014 Player *chr = getSelectedPlayer();
1015 if (chr == NULL)
1017 SendSysMessage(LANG_NO_CHAR_SELECTED);
1018 return true;
1021 PSendSysMessage(LANG_YOU_CHANGE_FLY_SPEED, FSpeed, chr->GetName());
1023 WorldPacket data;
1024 char buf[256];
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);
1032 return true;
1035 bool ChatHandler::HandleModifyScaleCommand(const char* args)
1037 if (!*args)
1038 return false;
1040 float Scale = (float)atof((char*)args);
1041 if (Scale > 3 || Scale <= 0)
1043 SendSysMessage(LANG_BAD_VALUE);
1044 return true;
1047 Player *chr = getSelectedPlayer();
1048 if (chr == NULL)
1050 SendSysMessage(LANG_NO_CHAR_SELECTED);
1051 return true;
1054 PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
1056 WorldPacket data;
1057 char buf[256];
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);
1065 return true;
1068 bool ChatHandler::HandleModifyMountCommand(const char* args)
1070 if(!*args)
1071 return false;
1073 uint16 mId = 1147;
1074 float speed = (float)15;
1075 uint32 num = 0;
1077 num = atoi((char*)args);
1078 switch(num)
1080 case 1:
1081 mId=14340;
1082 break;
1083 case 2:
1084 mId=4806;
1085 break;
1086 case 3:
1087 mId=6471;
1088 break;
1089 case 4:
1090 mId=12345;
1091 break;
1092 case 5:
1093 mId=6472;
1094 break;
1095 case 6:
1096 mId=6473;
1097 break;
1098 case 7:
1099 mId=10670;
1100 break;
1101 case 8:
1102 mId=10719;
1103 break;
1104 case 9:
1105 mId=10671;
1106 break;
1107 case 10:
1108 mId=10672;
1109 break;
1110 case 11:
1111 mId=10720;
1112 break;
1113 case 12:
1114 mId=14349;
1115 break;
1116 case 13:
1117 mId=11641;
1118 break;
1119 case 14:
1120 mId=12244;
1121 break;
1122 case 15:
1123 mId=12242;
1124 break;
1125 case 16:
1126 mId=14578;
1127 break;
1128 case 17:
1129 mId=14579;
1130 break;
1131 case 18:
1132 mId=14349;
1133 break;
1134 case 19:
1135 mId=12245;
1136 break;
1137 case 20:
1138 mId=14335;
1139 break;
1140 case 21:
1141 mId=207;
1142 break;
1143 case 22:
1144 mId=2328;
1145 break;
1146 case 23:
1147 mId=2327;
1148 break;
1149 case 24:
1150 mId=2326;
1151 break;
1152 case 25:
1153 mId=14573;
1154 break;
1155 case 26:
1156 mId=14574;
1157 break;
1158 case 27:
1159 mId=14575;
1160 break;
1161 case 28:
1162 mId=604;
1163 break;
1164 case 29:
1165 mId=1166;
1166 break;
1167 case 30:
1168 mId=2402;
1169 break;
1170 case 31:
1171 mId=2410;
1172 break;
1173 case 32:
1174 mId=2409;
1175 break;
1176 case 33:
1177 mId=2408;
1178 break;
1179 case 34:
1180 mId=2405;
1181 break;
1182 case 35:
1183 mId=14337;
1184 break;
1185 case 36:
1186 mId=6569;
1187 break;
1188 case 37:
1189 mId=10661;
1190 break;
1191 case 38:
1192 mId=10666;
1193 break;
1194 case 39:
1195 mId=9473;
1196 break;
1197 case 40:
1198 mId=9476;
1199 break;
1200 case 41:
1201 mId=9474;
1202 break;
1203 case 42:
1204 mId=14374;
1205 break;
1206 case 43:
1207 mId=14376;
1208 break;
1209 case 44:
1210 mId=14377;
1211 break;
1212 case 45:
1213 mId=2404;
1214 break;
1215 case 46:
1216 mId=2784;
1217 break;
1218 case 47:
1219 mId=2787;
1220 break;
1221 case 48:
1222 mId=2785;
1223 break;
1224 case 49:
1225 mId=2736;
1226 break;
1227 case 50:
1228 mId=2786;
1229 break;
1230 case 51:
1231 mId=14347;
1232 break;
1233 case 52:
1234 mId=14346;
1235 break;
1236 case 53:
1237 mId=14576;
1238 break;
1239 case 54:
1240 mId=9695;
1241 break;
1242 case 55:
1243 mId=9991;
1244 break;
1245 case 56:
1246 mId=6448;
1247 break;
1248 case 57:
1249 mId=6444;
1250 break;
1251 case 58:
1252 mId=6080;
1253 break;
1254 case 59:
1255 mId=6447;
1256 break;
1257 case 60:
1258 mId=4805;
1259 break;
1260 case 61:
1261 mId=9714;
1262 break;
1263 case 62:
1264 mId=6448;
1265 break;
1266 case 63:
1267 mId=6442;
1268 break;
1269 case 64:
1270 mId=14632;
1271 break;
1272 case 65:
1273 mId=14332;
1274 break;
1275 case 66:
1276 mId=14331;
1277 break;
1278 case 67:
1279 mId=8469;
1280 break;
1281 case 68:
1282 mId=2830;
1283 break;
1284 case 69:
1285 mId=2346;
1286 break;
1287 default:
1288 SendSysMessage(LANG_NO_MOUNT);
1289 return true;
1292 Player *chr = getSelectedPlayer();
1293 if (chr == NULL)
1295 SendSysMessage(LANG_NO_CHAR_SELECTED);
1296 return true;
1299 PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
1301 WorldPacket data;
1302 char buf[256];
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 );
1309 chr->Mount(mId);
1311 data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+4) );
1312 data.append(chr->GetPackGUID());
1313 data << (uint32)0;
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());
1319 data << (uint32)0;
1320 data << float(speed);
1321 chr->SendMessageToSet( &data, true );
1323 return true;
1326 bool ChatHandler::HandleModifyMoneyCommand(const char* args)
1328 if (!*args)
1329 return false;
1331 Player *chr = getSelectedPlayer();
1332 if (chr == NULL)
1334 SendSysMessage(LANG_NO_CHAR_SELECTED);
1335 return true;
1338 int32 addmoney = atoi((char*)args);
1340 uint32 moneyuser = m_session->GetPlayer()->GetMoney();
1342 if(addmoney < 0)
1344 int32 newmoney = moneyuser + addmoney;
1346 sLog.outDetail(LANG_CURRENT_MONEY, moneyuser, addmoney, newmoney);
1347 if(newmoney <= 0 )
1349 PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
1351 WorldPacket data;
1352 char buf[256];
1353 sprintf((char*)buf,LANG_YOURS_ALL_MONEY_GONE, m_session->GetPlayer()->GetName());
1354 FillSystemMessageData(&data, m_session, buf);
1355 chr->GetSession()->SendPacket(&data);
1357 chr->SetMoney(0);
1359 else
1361 PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
1363 WorldPacket data;
1364 char buf[256];
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 );
1372 else
1374 PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
1376 WorldPacket data;
1377 char buf[256];
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() );
1387 return true;
1390 bool ChatHandler::HandleModifyBitCommand(const char* args)
1392 if( !*args )
1393 return false;
1395 Player *chr = getSelectedPlayer();
1396 if (chr == NULL)
1398 SendSysMessage(LANG_NO_CHAR_SELECTED);
1399 return true;
1402 char* pField = strtok((char*)args, " ");
1403 if (!pField)
1404 return false;
1406 char* pBit = strtok(NULL, " ");
1407 if (!pBit)
1408 return false;
1410 uint16 field = atoi(pField);
1411 uint32 bit = atoi(pBit);
1413 if (field < 1 || field >= PLAYER_END)
1415 SendSysMessage(LANG_BAD_VALUE);
1416 return true;
1419 if (bit < 1 || bit > 32)
1421 SendSysMessage(LANG_BAD_VALUE);
1422 return true;
1425 if ( chr->HasFlag( field, (1<<(bit-1)) ) )
1427 chr->RemoveFlag( field, (1<<(bit-1)) );
1428 PSendSysMessage(LANG_REMOVE_BIT, bit, field);
1430 else
1432 chr->SetFlag( field, (1<<(bit-1)) );
1433 PSendSysMessage(LANG_SET_BIT, bit, field);
1436 return true;
1439 bool ChatHandler::HandleTeleCommand(const char * args)
1441 Player* _player = m_session->GetPlayer();
1443 if(_player->isInFlight())
1445 SendSysMessage(LANG_YOU_IN_FLIGHT);
1446 return true;
1449 char* cId = extractKeyFromLink((char*)args,"Htele"); // string or [name] Shift-click form |color|Htele:name|h[name]|h|r
1450 if(!cId)
1451 return false;
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());
1457 if (!result)
1459 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1460 return true;
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();
1468 delete result;
1470 if(!MapManager::IsValidMapCoord(mapid,x,y))
1472 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
1473 return true;
1476 _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
1478 _player->TeleportTo(mapid, x, y, z, ort);
1479 return true;
1482 bool ChatHandler::HandleLookupTeleCommand(const char * args)
1484 QueryResult *result;
1485 if(!*args)
1487 SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
1488 return true;
1490 char const* str = strtok((char*)args, " ");
1491 if(!str)
1492 return false;
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());
1497 if (!result)
1499 SendSysMessage(LANG_COMMAND_TELE_NOREQUEST);
1500 return true;
1502 std::string reply;
1503 for (uint64 i=0; i < result->GetRowCount(); i++)
1505 Field *fields = result->Fetch();
1506 reply += " |cffffffff|Htele:";
1507 reply += fields[0].GetCppString();
1508 reply += "|h[";
1509 reply += fields[0].GetCppString();
1510 reply += "]|h|r\n";
1511 result->NextRow();
1513 delete result;
1515 if(reply.empty())
1516 SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
1517 else
1519 reply = LANG_COMMAND_TELE_LOCATION + reply;
1520 SendSysMultilineMessage(reply.c_str());
1522 return true;
1525 bool ChatHandler::HandleWhispersCommand(const char* args)
1527 char* px = strtok((char*)args, " ");
1529 // ticket<end>
1530 if (!px)
1532 PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? LANG_ON : LANG_OFF);
1533 return true;
1536 // ticket on
1537 if(strncmp(px,"on",3) == 0)
1539 m_session->GetPlayer()->SetAcceptWhispers(true);
1540 SendSysMessage(LANG_COMMAND_WHISPERON);
1541 return true;
1544 // ticket off
1545 if(strncmp(px,"off",4) == 0)
1547 m_session->GetPlayer()->SetAcceptWhispers(false);
1548 SendSysMessage(LANG_COMMAND_WHISPEROFF);
1549 return true;
1552 return false;
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.
1561 if( *args )
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);
1572 return true;
1576 SendSysMessage(LANG_BAD_VALUE);
1577 return false;
1580 bool ChatHandler::HandleSaveAllCommand(const char* args)
1582 ObjectAccessor::Instance().SaveAllPlayers();
1583 SendSysMessage(LANG_PLAYERS_SAVED);
1584 return true;
1587 bool ChatHandler::HandleSendMailCommand(const char* args)
1589 if(!*args)
1590 return false;
1592 char* pName = strtok((char*)args, " ");
1593 char* msgSubject = strtok(NULL, " ");
1594 char* msgText = strtok(NULL, "");
1596 if (!msgText)
1597 return false;
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);
1620 if(receiver)
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());
1629 return true;
1632 bool ChatHandler::HandleNameTeleCommand(const char * args)
1634 char* pName = strtok((char*)args, " ");
1635 char* loc = strtok(NULL, "");
1637 if(!pName || !loc)
1638 return false;
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());
1647 if (!result)
1649 SendSysMessage(LANG_COMMAND_TELE_NOTFOUND);
1650 return true;
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();
1659 delete result;
1661 if(!MapManager::IsValidMapCoord(mapid,x,y))
1663 PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
1664 return true;
1667 Player *chr = objmgr.GetPlayer(name.c_str());
1668 if (chr)
1671 if(chr->IsBeingTeleported()==true)
1673 PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
1674 return true;
1677 if(chr->isInFlight())
1679 PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
1680 return true;
1683 PSendSysMessage(LANG_TELEPORTING_TO, chr->GetName(),"", location.c_str());
1685 if (m_session->GetPlayer()->isVisibleFor(chr))
1687 WorldPacket data;
1688 char buf0[256];
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);
1703 else
1704 PSendSysMessage(LANG_NO_PLAYER, name.c_str());
1706 return true;