Advertisement
Guest User

Untitled

a guest
Jul 12th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 20.90 KB | None | 0 0
  1. /*
  2. * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
  3. * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License along
  16. * with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18.  
  19. #include "Common.h"
  20. #include "DatabaseEnv.h"
  21. #include "WorldPacket.h"
  22. #include "WorldSession.h"
  23. #include "World.h"
  24. #include "ObjectMgr.h"
  25. #include "TicketMgr.h"
  26. #include "Player.h"
  27. #include "AccountMgr.h"
  28. #include "Opcodes.h"
  29. #include "Chat.h"
  30. #include "Log.h"
  31. #include "MapManager.h"
  32. #include "ObjectAccessor.h"
  33. #include "Language.h"
  34. #include "CellImpl.h"
  35. #include "InstanceSaveMgr.h"
  36. #include "Util.h"
  37. #include "Group.h"
  38.  
  39. #ifdef _DEBUG_VMAPS
  40. #include "VMapFactory.h"
  41. #endif
  42.  
  43. bool ChatHandler::HandleNameAnnounceCommand(const char* args)
  44. {
  45. if (!*args)
  46. return false;
  47.  
  48. std::string name("Console");
  49. if (WorldSession* session = GetSession())
  50. name = session->GetPlayer()->GetName();
  51.  
  52. sWorld->SendWorldText(LANG_ANNOUNCE_COLOR, name.c_str(), args);
  53. return true;
  54. }
  55.  
  56. bool ChatHandler::HandleGMNameAnnounceCommand(const char* args)
  57. {
  58. if (!*args)
  59. return false;
  60.  
  61. std::string name("Console");
  62. if (WorldSession* session = GetSession())
  63. name = session->GetPlayer()->GetName();
  64.  
  65. sWorld->SendGMText(LANG_GM_ANNOUNCE_COLOR, name.c_str(), args);
  66. return true;
  67. }
  68.  
  69. // global announce
  70. bool ChatHandler::HandleAnnounceCommand(const char* args)
  71. {
  72. if (!*args)
  73. return false;
  74.  
  75. char buff[2048];
  76. sprintf(buff, GetTrinityString(LANG_SYSTEMMESSAGE), args);
  77. sWorld->SendServerMessage(SERVER_MSG_STRING, buff);
  78. return true;
  79. }
  80.  
  81. // announce to logged in GMs
  82. bool ChatHandler::HandleGMAnnounceCommand(const char* args)
  83. {
  84. if (!*args)
  85. return false;
  86.  
  87. sWorld->SendGMText(LANG_GM_BROADCAST, args);
  88. return true;
  89. }
  90.  
  91. //notification player at the screen
  92. bool ChatHandler::HandleNotifyCommand(const char* args)
  93. {
  94. if (!*args)
  95. return false;
  96.  
  97. std::string str = GetTrinityString(LANG_GLOBAL_NOTIFY);
  98. str += args;
  99.  
  100. WorldPacket data(SMSG_NOTIFICATION, (str.size() + 1));
  101. data << str;
  102. sWorld->SendGlobalMessage(&data);
  103.  
  104. return true;
  105. }
  106.  
  107. //notification GM at the screen
  108. bool ChatHandler::HandleGMNotifyCommand(const char* args)
  109. {
  110. if (!*args)
  111. return false;
  112.  
  113. std::string str = GetTrinityString(LANG_GM_NOTIFY);
  114. str += args;
  115.  
  116. WorldPacket data(SMSG_NOTIFICATION, (str.size() + 1));
  117. data << str;
  118. sWorld->SendGlobalGMMessage(&data);
  119.  
  120. return true;
  121. }
  122.  
  123. //Summon Player
  124. bool ChatHandler::HandleSummonCommand(const char* args)
  125. {
  126. Player* target;
  127. uint64 target_guid;
  128. std::string target_name;
  129. if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
  130. return false;
  131.  
  132. Player* _player = m_session->GetPlayer();
  133. if (target == _player || target_guid == _player->GetGUID())
  134. {
  135. PSendSysMessage(LANG_CANT_TELEPORT_SELF);
  136. SetSentErrorMessage(true);
  137. return false;
  138. }
  139.  
  140. if (target)
  141. {
  142. std::string nameLink = playerLink(target_name);
  143. // check online security
  144. if (HasLowerSecurity(target, 0))
  145. return false;
  146.  
  147. if (target->IsBeingTeleported())
  148. {
  149. PSendSysMessage(LANG_IS_TELEPORTED, nameLink.c_str());
  150. SetSentErrorMessage(true);
  151. return false;
  152. }
  153.  
  154. Map* map = m_session->GetPlayer()->GetMap();
  155.  
  156. if (map->IsBattlegroundOrArena())
  157. {
  158. // only allow if gm mode is on
  159. if (!_player->isGameMaster())
  160. {
  161. PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM, nameLink.c_str());
  162. SetSentErrorMessage(true);
  163. return false;
  164. }
  165. // if both players are in different bgs
  166. else if (target->GetBattlegroundId() && m_session->GetPlayer()->GetBattlegroundId() != target->GetBattlegroundId())
  167. target->LeaveBattleground(false); // Note: should be changed so target gets no Deserter debuff
  168.  
  169. // all's well, set bg id
  170. // when porting out from the bg, it will be reset to 0
  171. target->SetBattlegroundId(m_session->GetPlayer()->GetBattlegroundId(), m_session->GetPlayer()->GetBattlegroundTypeId());
  172. // remember current position as entry point for return at bg end teleportation
  173. if (!target->GetMap()->IsBattlegroundOrArena())
  174. target->SetBattlegroundEntryPoint();
  175. }
  176. else if (map->IsDungeon())
  177. {
  178. Map* cMap = target->GetMap();
  179.  
  180. if (cMap->Instanceable() && cMap->GetInstanceId() != map->GetInstanceId())
  181. target->UnbindInstance(map->GetInstanceId(), target->GetDungeonDifficulty(), true);
  182.  
  183. // we are in instance, and can summon only player in our group with us as lead
  184. if (!m_session->GetPlayer()->GetGroup() || !target->GetGroup() ||
  185. (target->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
  186. (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()))
  187. // the last check is a bit excessive, but let it be, just in case
  188. {
  189. PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, nameLink.c_str());
  190. SetSentErrorMessage(true);
  191. return false;
  192. }
  193. }
  194.  
  195. PSendSysMessage(LANG_SUMMONING, nameLink.c_str(), "");
  196. if (needReportToTarget(target))
  197. ChatHandler(target).PSendSysMessage(LANG_SUMMONED_BY, playerLink(_player->GetName()).c_str());
  198.  
  199. // stop flight if need
  200. if (target->isInFlight())
  201. {
  202. target->GetMotionMaster()->MovementExpired();
  203. target->CleanupAfterTaxiFlight();
  204. }
  205. // save only in non-flight case
  206. else
  207. target->SaveRecallPosition();
  208.  
  209. // before GM
  210. float x, y, z;
  211. m_session->GetPlayer()->GetClosePoint(x, y, z, target->GetObjectSize());
  212. target->TeleportTo(m_session->GetPlayer()->GetMapId(), x, y, z, target->GetOrientation());
  213. target->SetPhaseMask(m_session->GetPlayer()->GetPhaseMask(), true);
  214. }
  215. else
  216. {
  217. // check offline security
  218. if (HasLowerSecurity(NULL, target_guid))
  219. return false;
  220.  
  221. std::string nameLink = playerLink(target_name);
  222.  
  223. PSendSysMessage(LANG_SUMMONING, nameLink.c_str(), GetTrinityString(LANG_OFFLINE));
  224.  
  225. // in point where GM stay
  226. Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
  227. m_session->GetPlayer()->GetPositionX(),
  228. m_session->GetPlayer()->GetPositionY(),
  229. m_session->GetPlayer()->GetPositionZ(),
  230. m_session->GetPlayer()->GetOrientation(),
  231. m_session->GetPlayer()->GetZoneId(),
  232. target_guid);
  233. }
  234.  
  235. return true;
  236. }
  237.  
  238. //Teleport to Player
  239. bool ChatHandler::HandleAppearCommand(const char* args)
  240. {
  241. Player* target;
  242. uint64 target_guid;
  243. std::string target_name;
  244. if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
  245. return false;
  246.  
  247. Player* _player = m_session->GetPlayer();
  248. if (target == _player || target_guid == _player->GetGUID())
  249. {
  250. SendSysMessage(LANG_CANT_TELEPORT_SELF);
  251. SetSentErrorMessage(true);
  252. return false;
  253. }
  254.  
  255. // Cannot appear to targets in combat (prevent vip abusers)
  256. if (_player->isInCombat())
  257. {
  258. SendSysMessage(LANG_YOU_IN_COMBAT);
  259. SetSentErrorMessage(true);
  260. return false;
  261. }
  262.  
  263.  
  264. if (target)
  265. {
  266. if ((_player->GetTeam() != target->GetTeam()) && _player->GetSession()->GetSecurity() > SEC_PLAYER)
  267. {
  268. SendSysMessage("You can only appear to your faction!");
  269. return false;
  270. }
  271. }
  272.  
  273.  
  274. if (target)
  275. {
  276. // check online security
  277. if (HasLowerSecurity(target, 0))
  278. return false;
  279.  
  280. std::string chrNameLink = playerLink(target_name);
  281.  
  282. Map* cMap = target->GetMap();
  283. if (cMap->IsBattlegroundOrArena())
  284. {
  285. // only allow if gm mode is on
  286. if (!_player->isGameMaster())
  287. {
  288. PSendSysMessage(LANG_CANNOT_GO_TO_BG_GM, chrNameLink.c_str());
  289. SetSentErrorMessage(true);
  290. return false;
  291. }
  292. // if both players are in different bgs
  293. else if (_player->GetBattlegroundId() && _player->GetBattlegroundId() != target->GetBattlegroundId())
  294. _player->LeaveBattleground(false); // Note: should be changed so _player gets no Deserter debuff
  295.  
  296. // all's well, set bg id
  297. // when porting out from the bg, it will be reset to 0
  298. _player->SetBattlegroundId(target->GetBattlegroundId(), target->GetBattlegroundTypeId());
  299. // remember current position as entry point for return at bg end teleportation
  300. if (!_player->GetMap()->IsBattlegroundOrArena())
  301. _player->SetBattlegroundEntryPoint();
  302. }
  303. else if (cMap->IsDungeon())
  304. {
  305. // we have to go to instance, and can go to player only if:
  306. // 1) we are in his group (either as leader or as member)
  307. // 2) we are not bound to any group and have GM mode on
  308. if (_player->GetGroup())
  309. {
  310. // we are in group, we can go only if we are in the player group
  311. if (_player->GetGroup() != target->GetGroup())
  312. {
  313. PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY, chrNameLink.c_str());
  314. SetSentErrorMessage(true);
  315. return false;
  316. }
  317. }
  318. else
  319. {
  320. // we are not in group, let's verify our GM mode
  321. if (!_player->isGameMaster())
  322. {
  323. PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM, chrNameLink.c_str());
  324. SetSentErrorMessage(true);
  325. return false;
  326. }
  327. }
  328.  
  329. // if the player or the player's group is bound to another instance
  330. // the player will not be bound to another one
  331. InstancePlayerBind* pBind = _player->GetBoundInstance(target->GetMapId(), target->GetDifficulty(cMap->IsRaid()));
  332. if (!pBind)
  333. {
  334. Group* group = _player->GetGroup();
  335. // if no bind exists, create a solo bind
  336. InstanceGroupBind* gBind = group ? group->GetBoundInstance(target) : NULL; // if no bind exists, create a solo bind
  337. if (!gBind)
  338. if (InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(target->GetInstanceId()))
  339. _player->BindToInstance(save, !save->CanReset());
  340. }
  341.  
  342. if (cMap->IsRaid())
  343. _player->SetRaidDifficulty(target->GetRaidDifficulty());
  344. else
  345. _player->SetDungeonDifficulty(target->GetDungeonDifficulty());
  346. }
  347.  
  348. PSendSysMessage(LANG_APPEARING_AT, chrNameLink.c_str());
  349.  
  350. // stop flight if need
  351. if (_player->isInFlight())
  352. {
  353. _player->GetMotionMaster()->MovementExpired();
  354. _player->CleanupAfterTaxiFlight();
  355. }
  356. // save only in non-flight case
  357. else
  358. _player->SaveRecallPosition();
  359.  
  360. // to point to see at target with same orientation
  361. float x, y, z;
  362. target->GetContactPoint(_player, x, y, z);
  363.  
  364. _player->TeleportTo(target->GetMapId(), x, y, z, _player->GetAngle(target), TELE_TO_GM_MODE);
  365. _player->SetPhaseMask(target->GetPhaseMask(), true);
  366. }
  367. else
  368. {
  369. // check offline security
  370. if (HasLowerSecurity(NULL, target_guid))
  371. return false;
  372.  
  373. std::string nameLink = playerLink(target_name);
  374.  
  375. PSendSysMessage(LANG_APPEARING_AT, nameLink.c_str());
  376.  
  377. // to point where player stay (if loaded)
  378. float x, y, z, o;
  379. uint32 map;
  380. bool in_flight;
  381. if (!Player::LoadPositionFromDB(map, x, y, z, o, in_flight, target_guid))
  382. return false;
  383.  
  384. // stop flight if need
  385. if (_player->isInFlight())
  386. {
  387. _player->GetMotionMaster()->MovementExpired();
  388. _player->CleanupAfterTaxiFlight();
  389. }
  390. // save only in non-flight case
  391. else
  392. _player->SaveRecallPosition();
  393.  
  394. _player->TeleportTo(map, x, y, z, _player->GetOrientation());
  395. }
  396.  
  397. return true;
  398. }
  399.  
  400. // Teleport player to last position
  401. bool ChatHandler::HandleRecallCommand(const char* args)
  402. {
  403. Player* target;
  404. if (!extractPlayerTarget((char*)args, &target))
  405. return false;
  406.  
  407. // check online security
  408. if (HasLowerSecurity(target, 0))
  409. return false;
  410.  
  411. if (target->IsBeingTeleported())
  412. {
  413. PSendSysMessage(LANG_IS_TELEPORTED, GetNameLink(target).c_str());
  414. SetSentErrorMessage(true);
  415. return false;
  416. }
  417.  
  418. // stop flight if need
  419. if (target->isInFlight())
  420. {
  421. target->GetMotionMaster()->MovementExpired();
  422. target->CleanupAfterTaxiFlight();
  423. }
  424.  
  425. target->TeleportTo(target->m_recallMap, target->m_recallX, target->m_recallY, target->m_recallZ, target->m_recallO);
  426. return true;
  427. }
  428.  
  429. //Enable On\OFF all taxi paths
  430. bool ChatHandler::HandleTaxiCheatCommand(const char* args)
  431. {
  432. if (!*args)
  433. {
  434. SendSysMessage(LANG_USE_BOL);
  435. SetSentErrorMessage(true);
  436. return false;
  437. }
  438.  
  439. std::string argstr = (char*)args;
  440.  
  441. Player* chr = getSelectedPlayer();
  442.  
  443. if (!chr)
  444. chr = m_session->GetPlayer();
  445. else if (HasLowerSecurity(chr, 0)) // check online security
  446. return false;
  447.  
  448. if (argstr == "on")
  449. {
  450. chr->SetTaxiCheater(true);
  451. PSendSysMessage(LANG_YOU_GIVE_TAXIS, GetNameLink(chr).c_str());
  452. if (needReportToTarget(chr))
  453. ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_ADDED, GetNameLink().c_str());
  454. return true;
  455. }
  456.  
  457. if (argstr == "off")
  458. {
  459. chr->SetTaxiCheater(false);
  460. PSendSysMessage(LANG_YOU_REMOVE_TAXIS, GetNameLink(chr).c_str());
  461. if (needReportToTarget(chr))
  462. ChatHandler(chr).PSendSysMessage(LANG_YOURS_TAXIS_REMOVED, GetNameLink().c_str());
  463.  
  464. return true;
  465. }
  466.  
  467. SendSysMessage(LANG_USE_BOL);
  468. SetSentErrorMessage(true);
  469. return false;
  470. }
  471.  
  472. bool ChatHandler::HandleLookupAreaCommand(const char* args)
  473. {
  474. if (!*args)
  475. return false;
  476.  
  477. std::string namepart = args;
  478. std::wstring wnamepart;
  479.  
  480. if (!Utf8toWStr(namepart, wnamepart))
  481. return false;
  482.  
  483. bool found = false;
  484. uint32 count = 0;
  485. uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
  486.  
  487. // converting string that we try to find to lower case
  488. wstrToLower(wnamepart);
  489.  
  490. // Search in AreaTable.dbc
  491. for (uint32 areaflag = 0; areaflag < sAreaStore.GetNumRows(); ++areaflag)
  492. {
  493. AreaTableEntry const* areaEntry = sAreaStore.LookupEntry(areaflag);
  494. if (areaEntry)
  495. {
  496. int loc = GetSessionDbcLocale();
  497. std::string name = areaEntry->area_name[loc];
  498. if (name.empty())
  499. continue;
  500.  
  501. if (!Utf8FitTo(name, wnamepart))
  502. {
  503. loc = 0;
  504. for (; loc < TOTAL_LOCALES; ++loc)
  505. {
  506. if (loc == GetSessionDbcLocale())
  507. continue;
  508.  
  509. name = areaEntry->area_name[loc];
  510. if (name.empty())
  511. continue;
  512.  
  513. if (Utf8FitTo(name, wnamepart))
  514. break;
  515. }
  516. }
  517.  
  518. if (loc < TOTAL_LOCALES)
  519. {
  520. if (maxResults && count++ == maxResults)
  521. {
  522. PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults);
  523. return true;
  524. }
  525.  
  526. // send area in "id - [name]" format
  527. std::ostringstream ss;
  528. if (m_session)
  529. ss << areaEntry->ID << " - |cffffffff|Harea:" << areaEntry->ID << "|h[" << name << ' ' << localeNames[loc] << "]|h|r";
  530. else
  531. ss << areaEntry->ID << " - " << name << ' ' << localeNames[loc];
  532.  
  533. SendSysMessage(ss.str().c_str());
  534.  
  535. if (!found)
  536. found = true;
  537. }
  538. }
  539. }
  540.  
  541. if (!found)
  542. SendSysMessage(LANG_COMMAND_NOAREAFOUND);
  543.  
  544. return true;
  545. }
  546.  
  547. //Find tele in game_tele order by name
  548. bool ChatHandler::HandleLookupTeleCommand(const char * args)
  549. {
  550. if (!*args)
  551. {
  552. SendSysMessage(LANG_COMMAND_TELE_PARAMETER);
  553. SetSentErrorMessage(true);
  554. return false;
  555. }
  556.  
  557. char const* str = strtok((char*)args, " ");
  558. if (!str)
  559. return false;
  560.  
  561. std::string namepart = str;
  562. std::wstring wnamepart;
  563.  
  564. if (!Utf8toWStr(namepart, wnamepart))
  565. return false;
  566.  
  567. // converting string that we try to find to lower case
  568. wstrToLower(wnamepart);
  569.  
  570. std::ostringstream reply;
  571. uint32 count = 0;
  572. uint32 maxResults = sWorld->getIntConfig(CONFIG_MAX_RESULTS_LOOKUP_COMMANDS);
  573. bool limitReached = false;
  574.  
  575. GameTeleContainer const & teleMap = sObjectMgr->GetGameTeleMap();
  576. for (GameTeleContainer::const_iterator itr = teleMap.begin(); itr != teleMap.end(); ++itr)
  577. {
  578. GameTele const* tele = &itr->second;
  579.  
  580. if (tele->wnameLow.find(wnamepart) == std::wstring::npos)
  581. continue;
  582.  
  583. if (maxResults && count++ == maxResults)
  584. {
  585. limitReached = true;
  586. break;
  587. }
  588.  
  589. if (m_session)
  590. reply << " |cffffffff|Htele:" << itr->first << "|h[" << tele->name << "]|h|r\n";
  591. else
  592. reply << " " << itr->first << ' ' << tele->name << "\n";
  593. }
  594.  
  595. if (reply.str().empty())
  596. SendSysMessage(LANG_COMMAND_TELE_NOLOCATION);
  597. else
  598. PSendSysMessage(LANG_COMMAND_TELE_LOCATION, reply.str().c_str());
  599.  
  600. if (limitReached)
  601. PSendSysMessage(LANG_COMMAND_LOOKUP_MAX_RESULTS, maxResults);
  602.  
  603. return true;
  604. }
  605.  
  606. //Enable\Dissable accept whispers (for GM)
  607. bool ChatHandler::HandleWhispersCommand(const char* args)
  608. {
  609. if (!*args)
  610. {
  611. PSendSysMessage(LANG_COMMAND_WHISPERACCEPTING, m_session->GetPlayer()->isAcceptWhispers() ? GetTrinityString(LANG_ON) : GetTrinityString(LANG_OFF));
  612. return true;
  613. }
  614.  
  615. std::string argstr = (char*)args;
  616. // whisper on
  617. if (argstr == "on")
  618. {
  619. m_session->GetPlayer()->SetAcceptWhispers(true);
  620. SendSysMessage(LANG_COMMAND_WHISPERON);
  621. return true;
  622. }
  623.  
  624. // whisper off
  625. if (argstr == "off")
  626. {
  627. // Remove all players from the Gamemaster's whisper whitelist
  628. m_session->GetPlayer()->ClearWhisperWhiteList();
  629. m_session->GetPlayer()->SetAcceptWhispers(false);
  630. SendSysMessage(LANG_COMMAND_WHISPEROFF);
  631. return true;
  632. }
  633.  
  634. SendSysMessage(LANG_USE_BOL);
  635. SetSentErrorMessage(true);
  636. return false;
  637. }
  638.  
  639. //Save all players in the world
  640. bool ChatHandler::HandleSaveAllCommand(const char* /*args*/)
  641. {
  642. sObjectAccessor->SaveAllPlayers();
  643. SendSysMessage(LANG_PLAYERS_SAVED);
  644. return true;
  645. }
  646.  
  647. //Send mail by command
  648. bool ChatHandler::HandleSendMailCommand(const char* args)
  649. {
  650. // format: name "subject text" "mail text"
  651. Player* target;
  652. uint64 target_guid;
  653. std::string target_name;
  654. if (!extractPlayerTarget((char*)args, &target, &target_guid, &target_name))
  655. return false;
  656.  
  657. char* tail1 = strtok(NULL, "");
  658. if (!tail1)
  659. return false;
  660.  
  661. char* msgSubject = extractQuotedArg(tail1);
  662. if (!msgSubject)
  663. return false;
  664.  
  665. char* tail2 = strtok(NULL, "");
  666. if (!tail2)
  667. return false;
  668.  
  669. char* msgText = extractQuotedArg(tail2);
  670. if (!msgText)
  671. return false;
  672.  
  673. // msgSubject, msgText isn't NUL after prev. check
  674. std::string subject = msgSubject;
  675. std::string text = msgText;
  676.  
  677. // from console show not existed sender
  678. MailSender sender(MAIL_NORMAL, m_session ? m_session->GetPlayer()->GetGUIDLow() : 0, MAIL_STATIONERY_GM);
  679.  
  680. //- TODO: Fix poor design
  681. SQLTransaction trans = CharacterDatabase.BeginTransaction();
  682. MailDraft(subject, text)
  683. .SendMailTo(trans, MailReceiver(target, GUID_LOPART(target_guid)), sender);
  684.  
  685. CharacterDatabase.CommitTransaction(trans);
  686.  
  687. std::string nameLink = playerLink(target_name);
  688. PSendSysMessage(LANG_MAIL_SENT, nameLink.c_str());
  689. return true;
  690. }
  691.  
  692. //Summon group of player
  693. bool ChatHandler::HandleGroupSummonCommand(const char* args)
  694. {
  695. Player* target;
  696. if (!extractPlayerTarget((char*)args, &target))
  697. return false;
  698.  
  699. // check online security
  700. if (HasLowerSecurity(target, 0))
  701. return false;
  702.  
  703. Group* grp = target->GetGroup();
  704.  
  705. std::string nameLink = GetNameLink(target);
  706.  
  707. if (!grp)
  708. {
  709. PSendSysMessage(LANG_NOT_IN_GROUP, nameLink.c_str());
  710. SetSentErrorMessage(true);
  711. return false;
  712. }
  713.  
  714. Map* gmMap = m_session->GetPlayer()->GetMap();
  715. bool to_instance = gmMap->Instanceable();
  716.  
  717. // we are in instance, and can summon only player in our group with us as lead
  718. if (to_instance && (
  719. !m_session->GetPlayer()->GetGroup() || (grp->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
  720. (m_session->GetPlayer()->GetGroup()->GetLeaderGUID() != m_session->GetPlayer()->GetGUID())))
  721. // the last check is a bit excessive, but let it be, just in case
  722. {
  723. SendSysMessage(LANG_CANNOT_SUMMON_TO_INST);
  724. SetSentErrorMessage(true);
  725. return false;
  726. }
  727.  
  728. for (GroupReference* itr = grp->GetFirstMember(); itr != NULL; itr = itr->next())
  729. {
  730. Player* player = itr->getSource();
  731.  
  732. if (!player || player == m_session->GetPlayer() || !player->GetSession())
  733. continue;
  734.  
  735. // check online security
  736. if (HasLowerSecurity(player, 0))
  737. return false;
  738.  
  739. std::string plNameLink = GetNameLink(player);
  740.  
  741. if (player->IsBeingTeleported() == true)
  742. {
  743. PSendSysMessage(LANG_IS_TELEPORTED, plNameLink.c_str());
  744. SetSentErrorMessage(true);
  745. return false;
  746. }
  747.  
  748. if (to_instance)
  749. {
  750. Map* plMap = player->GetMap();
  751.  
  752. if (plMap->Instanceable() && plMap->GetInstanceId() != gmMap->GetInstanceId())
  753. {
  754. // cannot summon from instance to instance
  755. PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST, plNameLink.c_str());
  756. SetSentErrorMessage(true);
  757. return false;
  758. }
  759. }
  760.  
  761. PSendSysMessage(LANG_SUMMONING, plNameLink.c_str(), "");
  762. if (needReportToTarget(player))
  763. ChatHandler(player).PSendSysMessage(LANG_SUMMONED_BY, GetNameLink().c_str());
  764.  
  765. // stop flight if need
  766. if (player->isInFlight())
  767. {
  768. player->GetMotionMaster()->MovementExpired();
  769. player->CleanupAfterTaxiFlight();
  770. }
  771. // save only in non-flight case
  772. else
  773. player->SaveRecallPosition();
  774.  
  775. // before GM
  776. float x, y, z;
  777. m_session->GetPlayer()->GetClosePoint(x, y, z, player->GetObjectSize());
  778. player->TeleportTo(m_session->GetPlayer()->GetMapId(), x, y, z, player->GetOrientation());
  779. }
  780.  
  781. return true;
  782. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement