PageRenderTime 54ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/game/Level1.cpp

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