PageRenderTime 37ms CodeModel.GetById 8ms RepoModel.GetById 0ms app.codeStats 0ms

/src/game/Level1.cpp

https://github.com/Aion/caldari
C++ | 1462 lines | 1137 code | 252 blank | 73 comment | 157 complexity | 4b0c79e0c1588f06ef6bba69a36b18d3 MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. * Copyright (C) 2005,2006,2007 MaNGOS <http://www.mangosproject.org/>
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation; either version 2 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program; if not, write to the Free Software
  16. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. */
  18. #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 "RedZoneDistrict.h"
  32. #include "Transports.h"
  33. bool ChatHandler::HandleAnnounceCommand(const char* args)
  34. {
  35. if(!*args)
  36. return false;
  37. std::string str ="|cffff0000[System Message]:|r";
  38. str += args;
  39. sWorld.SendWorldText(str.c_str(), NULL);
  40. return true;
  41. }
  42. bool ChatHandler::HandleGMOnCommand(const char* args)
  43. {
  44. m_session->GetPlayer()->SetGameMaster(true);
  45. m_session->SendNotification("GM mode is ON");
  46. return true;
  47. }
  48. bool ChatHandler::HandleGMOffCommand(const char* args)
  49. {
  50. m_session->GetPlayer()->SetGameMaster(false);
  51. m_session->SendNotification("GM mode is OFF");
  52. return true;
  53. }
  54. bool ChatHandler::HandleVisibleCommand(const char* args)
  55. {
  56. int option = atoi((char*)args);
  57. if (option != 0 && option != 1 || !*args)
  58. {
  59. SendSysMessage(LANG_USE_BOL);
  60. PSendSysMessage("Your are: %s", m_session->GetPlayer()->isGMVisible() ? "visible" : "invisible");
  61. return true;
  62. }
  63. if ( option )
  64. {
  65. m_session->GetPlayer()->SetGMVisible(true);
  66. m_session->SendNotification( LANG_INVISIBLE_VISIBLE );
  67. }
  68. else
  69. {
  70. m_session->SendNotification( LANG_INVISIBLE_INVISIBLE );
  71. m_session->GetPlayer()->SetGMVisible(false);
  72. }
  73. return true;
  74. }
  75. bool ChatHandler::HandleGPSCommand(const char* args)
  76. {
  77. WorldObject *obj = getSelectedUnit();
  78. if(!obj)
  79. {
  80. SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
  81. return true;
  82. }
  83. CellPair cell_val = MaNGOS::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY());
  84. Cell cell = RedZone::GetZone(cell_val);
  85. PSendSysMultilineMessage(LANG_MAP_POSITION,
  86. obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
  87. obj->GetOrientation(),cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
  88. sLog.outDebug("Player %s GPS call %s %u " LANG_MAP_POSITION, m_session->GetPlayer()->GetName(),
  89. (obj->GetTypeId() == TYPEID_PLAYER ? "player" : "creature"), obj->GetGUIDLow(),
  90. obj->GetMapId(), obj->GetZoneId(), obj->GetPositionX(), obj->GetPositionY(), obj->GetPositionZ(),
  91. obj->GetOrientation(), cell.GridX(), cell.GridY(), cell.CellX(), cell.CellY());
  92. return true;
  93. }
  94. bool ChatHandler::HandleNamegoCommand(const char* args)
  95. {
  96. WorldPacket data;
  97. if(m_session->GetPlayer()->isInFlight())
  98. {
  99. SendSysMessage(LANG_YOU_IN_FLIGHT);
  100. return true;
  101. }
  102. if(!*args)
  103. return false;
  104. std::string name = args;
  105. normalizePlayerName(name);
  106. sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
  107. Player *chr = objmgr.GetPlayer(name.c_str());
  108. if (chr)
  109. {
  110. if(chr->IsBeingTeleported()==true)
  111. {
  112. PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
  113. return true;
  114. }
  115. if(chr->isInFlight())
  116. {
  117. PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
  118. return true;
  119. }
  120. if (MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(), m_session->GetPlayer())->Instanceable())
  121. {
  122. if ( (MapManager::Instance().GetMap(chr->GetMapId(), chr)->Instanceable()) &&
  123. (MapManager::Instance().GetMap(chr->GetMapId(), chr)->GetInstanceId() !=
  124. MapManager::Instance().GetMap(m_session->GetPlayer()->GetMapId(), m_session->GetPlayer())->GetInstanceId()) )
  125. {
  126. // cannot summon from instance to instance
  127. PSendSysMessage(LANG_CANNOT_INST_INST);
  128. return true;
  129. }
  130. // we are in instance, and can summon only player in our group with us as lead
  131. if ( !m_session->GetPlayer()->groupInfo.group || !chr->groupInfo.group ||
  132. (chr->groupInfo.group->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) ||
  133. (m_session->GetPlayer()->groupInfo.group->GetLeaderGUID() != m_session->GetPlayer()->GetGUID()) )
  134. // the last check is a bit excessive, but let it be, just in case
  135. {
  136. PSendSysMessage(LANG_CANNOT_SUMMON_TO_INST,chr->GetName());
  137. return true;
  138. }
  139. }
  140. PSendSysMessage(LANG_SUMMONING, chr->GetName(),"");
  141. if (m_session->GetPlayer()->isVisibleFor(chr,false))
  142. {
  143. char buf0[256];
  144. snprintf((char*)buf0,256,LANG_SUMMONED_BY, m_session->GetPlayer()->GetName());
  145. FillSystemMessageData(&data, m_session, buf0);
  146. chr->GetSession()->SendPacket( &data );
  147. }
  148. chr->SetRecallPosition(chr->GetMapId(),chr->GetPositionX(),chr->GetPositionY(),chr->GetPositionZ(),chr->GetOrientation());
  149. // before GM
  150. float x,y,z;
  151. m_session->GetPlayer()->GetClosePoint(NULL,x,y,z,chr->GetObjectSize());
  152. chr->TeleportTo(m_session->GetPlayer()->GetMapId(),x,y,z,chr->GetOrientation());
  153. }
  154. else if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
  155. {
  156. PSendSysMessage(LANG_SUMMONING, name.c_str()," (offline)");
  157. // in point where GM stay
  158. Player::SavePositionInDB(m_session->GetPlayer()->GetMapId(),
  159. m_session->GetPlayer()->GetPositionX(),
  160. m_session->GetPlayer()->GetPositionY(),
  161. m_session->GetPlayer()->GetPositionZ(),m_session->GetPlayer()->GetOrientation(),guid);
  162. }
  163. else
  164. PSendSysMessage(LANG_NO_PLAYER, args);
  165. return true;
  166. }
  167. bool ChatHandler::HandleGonameCommand(const char* args)
  168. {
  169. Player* _player = m_session->GetPlayer();
  170. if(_player->isInFlight())
  171. {
  172. SendSysMessage(LANG_YOU_IN_FLIGHT);
  173. return true;
  174. }
  175. if(!*args)
  176. return false;
  177. std::string name = args;
  178. normalizePlayerName(name);
  179. sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
  180. Player *chr = objmgr.GetPlayer(name.c_str());
  181. if (chr)
  182. {
  183. if (MapManager::Instance().GetMap(chr->GetMapId(), chr)->Instanceable())
  184. {
  185. if ( (MapManager::Instance().GetMap(_player->GetMapId(), _player)->Instanceable()) &&
  186. (MapManager::Instance().GetMap(chr->GetMapId(), chr)->GetInstanceId() !=
  187. MapManager::Instance().GetMap(_player->GetMapId(), _player)->GetInstanceId()) )
  188. {
  189. // cannot go from instance to instance
  190. PSendSysMessage(LANG_CANNOT_INST_INST);
  191. return true;
  192. }
  193. // we have to go to instance, and can go to player only if:
  194. // 1) we are in his group (either as leader or as member)
  195. // 2) we are not bound to any group and have GM mode on
  196. if (_player->groupInfo.group)
  197. {
  198. // we are in group, we can go only if we are in the player group
  199. if (_player->groupInfo.group != chr->groupInfo.group)
  200. {
  201. PSendSysMessage(LANG_CANNOT_GO_TO_INST_PARTY,chr->GetName());
  202. return true;
  203. }
  204. }
  205. else
  206. {
  207. // we are not in group, let's verify our GM mode
  208. if (!_player->isGameMaster())
  209. {
  210. PSendSysMessage(LANG_CANNOT_GO_TO_INST_GM,chr->GetName());
  211. return true;
  212. }
  213. }
  214. // bind us to the players instance
  215. BoundInstancesMap::iterator i = chr->m_BoundInstances.find(chr->GetMapId());
  216. if (i == chr->m_BoundInstances.end()) return true; // error, the player has no instance bound!!!
  217. _player->m_BoundInstances[chr->GetMapId()] = std::pair < uint32, uint32 >(i->second.first, i->second.second);
  218. _player->SetInstanceId(chr->GetInstanceId());
  219. }
  220. PSendSysMessage(LANG_APPEARING_AT, chr->GetName());
  221. if (_player->isVisibleFor(chr,false))
  222. {
  223. char buf0[256];
  224. sprintf((char*)buf0,LANG_APPEARING_TO, _player->GetName());
  225. WorldPacket data;
  226. FillSystemMessageData(&data, m_session, buf0);
  227. chr->GetSession()->SendPacket(&data);
  228. }
  229. _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
  230. // to point to see at target with same orientation
  231. float x,y,z;
  232. chr->GetContactPoint(m_session->GetPlayer(),x,y,z);
  233. _player->TeleportTo(chr->GetMapId(), x, y, z, _player->GetAngle( chr ), true, true, true);
  234. return true;
  235. }
  236. if (uint64 guid = objmgr.GetPlayerGUIDByName(name.c_str()))
  237. {
  238. PSendSysMessage(LANG_APPEARING_AT, name.c_str());
  239. // to point where player stay (if loaded)
  240. float x,y,z,o;
  241. uint32 map;
  242. if(Player::LoadPositionFromDB(map,x,y,z,o,guid))
  243. {
  244. _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
  245. _player->TeleportTo(map, x, y, z,_player->GetOrientation());
  246. return true;
  247. }
  248. }
  249. PSendSysMessage(LANG_NO_PLAYER, args);
  250. return true;
  251. }
  252. bool ChatHandler::HandleRecallCommand(const char* args)
  253. {
  254. Player* chr = NULL;
  255. if(!*args)
  256. {
  257. chr = getSelectedPlayer();
  258. if(!chr)
  259. {
  260. chr = m_session->GetPlayer();
  261. if(chr->isInFlight())
  262. {
  263. SendSysMessage(LANG_YOU_IN_FLIGHT);
  264. return true;
  265. }
  266. }
  267. }
  268. else
  269. {
  270. std::string name = args;
  271. normalizePlayerName(name);
  272. sDatabase.escape_string(name); // prevent SQL injection - normal name don't must changed by this call
  273. chr = objmgr.GetPlayer(name.c_str());
  274. if(!chr)
  275. {
  276. PSendSysMessage(LANG_NO_PLAYER, args);
  277. return true;
  278. }
  279. }
  280. if(chr->IsBeingTeleported())
  281. {
  282. PSendSysMessage(LANG_IS_TELEPORTED, chr->GetName());
  283. return true;
  284. }
  285. if(chr->isInFlight())
  286. {
  287. PSendSysMessage(LANG_CHAR_IN_FLIGHT, chr->GetName());
  288. return true;
  289. }
  290. chr->TeleportTo(chr->m_recallMap, chr->m_recallX, chr->m_recallY, chr->m_recallZ, chr->m_recallO);
  291. return true;
  292. }
  293. bool ChatHandler::HandleModifyHPCommand(const char* args)
  294. {
  295. WorldPacket data;
  296. // char* pHp = strtok((char*)args, " ");
  297. // if (!pHp)
  298. // return false;
  299. // char* pHpMax = strtok(NULL, " ");
  300. // if (!pHpMax)
  301. // return false;
  302. // int32 hpm = atoi(pHpMax);
  303. // int32 hp = atoi(pHp);
  304. int32 hp = atoi((char*)args);
  305. int32 hpm = atoi((char*)args);
  306. if (hp <= 0 || hpm <= 0 || hpm < hp)
  307. {
  308. SendSysMessage(LANG_BAD_VALUE);
  309. return true;
  310. }
  311. Player *chr = getSelectedPlayer();
  312. if (chr == NULL)
  313. {
  314. SendSysMessage(LANG_NO_CHAR_SELECTED);
  315. return true;
  316. }
  317. PSendSysMessage(LANG_YOU_CHANGE_HP, hp, hpm, chr->GetName());
  318. char buf[256];
  319. sprintf((char*)buf,LANG_YOURS_HP_CHANGED, m_session->GetPlayer()->GetName(), hp, hpm);
  320. FillSystemMessageData(&data, m_session, buf);
  321. chr->GetSession()->SendPacket(&data);
  322. chr->SetMaxHealth( hpm );
  323. chr->SetHealth( hp );
  324. return true;
  325. }
  326. bool ChatHandler::HandleModifyManaCommand(const char* args)
  327. {
  328. WorldPacket data;
  329. // char* pmana = strtok((char*)args, " ");
  330. // if (!pmana)
  331. // return false;
  332. // char* pmanaMax = strtok(NULL, " ");
  333. // if (!pmanaMax)
  334. // return false;
  335. // int32 manam = atoi(pmanaMax);
  336. // int32 mana = atoi(pmana);
  337. int32 mana = atoi((char*)args);
  338. int32 manam = atoi((char*)args);
  339. if (mana <= 0 || manam <= 0 || manam < mana)
  340. {
  341. SendSysMessage(LANG_BAD_VALUE);
  342. return true;
  343. }
  344. Player *chr = getSelectedPlayer();
  345. if (chr == NULL)
  346. {
  347. SendSysMessage(LANG_NO_CHAR_SELECTED);
  348. return true;
  349. }
  350. PSendSysMessage(LANG_YOU_CHANGE_MANA, mana, manam, chr->GetName());
  351. char buf[256];
  352. sprintf((char*)buf,LANG_YOURS_MANA_CHANGED, m_session->GetPlayer()->GetName(), mana, manam);
  353. FillSystemMessageData(&data, m_session, buf);
  354. chr->GetSession()->SendPacket(&data);
  355. chr->SetMaxPower(POWER_MANA,manam );
  356. chr->SetPower(POWER_MANA, mana );
  357. return true;
  358. }
  359. bool ChatHandler::HandleModifyEnergyCommand(const char* args)
  360. {
  361. WorldPacket data;
  362. // char* pmana = strtok((char*)args, " ");
  363. // if (!pmana)
  364. // return false;
  365. // char* pmanaMax = strtok(NULL, " ");
  366. // if (!pmanaMax)
  367. // return false;
  368. // int32 manam = atoi(pmanaMax);
  369. // int32 mana = atoi(pmana);
  370. int32 mana = atoi((char*)args)*10;
  371. int32 manam = atoi((char*)args)*10;
  372. if (mana <= 0 || manam <= 0 || manam < mana)
  373. {
  374. SendSysMessage(LANG_BAD_VALUE);
  375. return true;
  376. }
  377. Player *chr = getSelectedPlayer();
  378. if (chr == NULL)
  379. {
  380. PSendSysMessage(LANG_NO_CHAR_SELECTED);
  381. return true;
  382. }
  383. PSendSysMessage(LANG_YOU_CHANGE_ENERGY, mana/10, manam/10, chr->GetName());
  384. char buf[256];
  385. sprintf((char*)buf,LANG_YOURS_ENERGY_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
  386. FillSystemMessageData(&data, m_session, buf);
  387. chr->GetSession()->SendPacket(&data);
  388. chr->SetMaxPower(POWER_ENERGY,manam );
  389. chr->SetPower(POWER_ENERGY, mana );
  390. sLog.outDetail(LANG_CURRENT_ENERGY,chr->GetMaxPower(POWER_ENERGY));
  391. return true;
  392. }
  393. bool ChatHandler::HandleModifyRageCommand(const char* args)
  394. {
  395. WorldPacket data;
  396. // char* pmana = strtok((char*)args, " ");
  397. // if (!pmana)
  398. // return false;
  399. // char* pmanaMax = strtok(NULL, " ");
  400. // if (!pmanaMax)
  401. // return false;
  402. // int32 manam = atoi(pmanaMax);
  403. // int32 mana = atoi(pmana);
  404. int32 mana = atoi((char*)args)*10;
  405. int32 manam = atoi((char*)args)*10;
  406. if (mana <= 0 || manam <= 0 || manam < mana)
  407. {
  408. SendSysMessage(LANG_BAD_VALUE);
  409. return true;
  410. }
  411. Player *chr = getSelectedPlayer();
  412. if (chr == NULL)
  413. {
  414. SendSysMessage(LANG_NO_CHAR_SELECTED);
  415. return true;
  416. }
  417. PSendSysMessage(LANG_YOU_CHANGE_RAGE, mana/10, manam/10, chr->GetName());
  418. char buf[256];
  419. sprintf((char*)buf,LANG_YOURS_RAGE_CHANGED, m_session->GetPlayer()->GetName(), mana/10, manam/10);
  420. FillSystemMessageData(&data, m_session, buf);
  421. chr->GetSession()->SendPacket(&data);
  422. chr->SetMaxPower(POWER_RAGE,manam );
  423. chr->SetPower(POWER_RAGE, mana );
  424. return true;
  425. }
  426. bool ChatHandler::HandleModifyFactionCommand(const char* args)
  427. {
  428. uint32 factionid;
  429. uint32 flag;
  430. uint32 npcflag;
  431. uint32 dyflag;
  432. char* pfactionid = strtok((char*)args, " ");
  433. Creature* chr = getSelectedCreature();
  434. if(!chr)
  435. {
  436. SendSysMessage(LANG_SELECT_CREATURE);
  437. return true;
  438. }
  439. if(!pfactionid)
  440. {
  441. if(chr)
  442. {
  443. factionid = chr->getFaction();
  444. flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
  445. npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
  446. dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
  447. PSendSysMessage(LANG_CURRENT_FACTION,chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
  448. }
  449. return true;
  450. }
  451. if (chr == NULL)
  452. {
  453. SendSysMessage(LANG_NO_CHAR_SELECTED);
  454. return true;
  455. }
  456. factionid = atoi(pfactionid);
  457. char* pflag = strtok(NULL, " ");
  458. if (!pflag)
  459. flag = chr->GetUInt32Value(UNIT_FIELD_FLAGS);
  460. else
  461. flag = atoi(pflag);
  462. char* pnpcflag = strtok(NULL, " ");
  463. if(!pnpcflag)
  464. npcflag = chr->GetUInt32Value(UNIT_NPC_FLAGS);
  465. else
  466. npcflag = atoi(pnpcflag);
  467. char* pdyflag = strtok(NULL, " ");
  468. if(!pdyflag)
  469. dyflag = chr->GetUInt32Value(UNIT_DYNAMIC_FLAGS);
  470. else
  471. dyflag = atoi(pdyflag);
  472. if(!sFactionTemplateStore.LookupEntry(factionid))
  473. {
  474. PSendSysMessage(LANG_WRONG_FACTION, factionid);
  475. return true;
  476. }
  477. PSendSysMessage(LANG_YOU_CHANGE_FACTION, chr->GetGUIDLow(),factionid,flag,npcflag,dyflag);
  478. //sprintf((char*)buf,"%s changed your Faction to %i.", m_session->GetPlayer()->GetName(), factionid);
  479. //FillSystemMessageData(&data, m_session, buf);
  480. //chr->GetSession()->SendPacket(&data);
  481. chr->setFaction(factionid);
  482. chr->SetUInt32Value(UNIT_FIELD_FLAGS,flag);
  483. chr->SetUInt32Value(UNIT_NPC_FLAGS,npcflag);
  484. chr->SetUInt32Value(UNIT_DYNAMIC_FLAGS,dyflag);
  485. return true;
  486. }
  487. bool ChatHandler::HandleModifySpellCommand(const char* args)
  488. {
  489. WorldPacket data;
  490. char* pspellflatid = strtok((char*)args, " ");
  491. if (!pspellflatid)
  492. return false;
  493. char* pop = strtok(NULL, " ");
  494. if (!pop)
  495. return false;
  496. char* pval = strtok(NULL, " ");
  497. if (!pval)
  498. return false;
  499. uint16 mark;
  500. char* pmark = strtok(NULL, " ");
  501. uint8 spellflatid = atoi(pspellflatid);
  502. uint8 op = atoi(pop);
  503. uint16 val = atoi(pval);
  504. if(!pmark)
  505. mark = 65535;
  506. else
  507. mark = atoi(pmark);
  508. Player *chr = getSelectedPlayer();
  509. if (chr == NULL)
  510. {
  511. SendSysMessage(LANG_NO_CHAR_SELECTED);
  512. return true;
  513. }
  514. PSendSysMessage(LANG_YOU_CHANGE_SPELLFLATID, spellflatid, val, mark, chr->GetName());
  515. char buf[256];
  516. sprintf((char*)buf,LANG_YOURS_SPELLFLATID_CHANGED, m_session->GetPlayer()->GetName(), spellflatid, val, mark);
  517. FillSystemMessageData(&data, m_session, buf);
  518. chr->GetSession()->SendPacket(&data);
  519. data.Initialize(SMSG_SET_FLAT_SPELL_MODIFIER, (1+1+2+2));
  520. data << uint8(spellflatid);
  521. data << uint8(op);
  522. data << uint16(val);
  523. data << uint16(mark);
  524. chr->GetSession()->SendPacket(&data);
  525. return true;
  526. }
  527. bool ChatHandler::HandleModifyTalentCommand (const char* args)
  528. {
  529. int tp = atoi((char*)args);
  530. if (tp>0)
  531. {
  532. Player* player = getSelectedPlayer();
  533. if(!player)
  534. {
  535. SendSysMessage(LANG_NO_CHAR_SELECTED);
  536. return true;
  537. }
  538. player->SetUInt32Value(PLAYER_CHARACTER_POINTS1, tp);
  539. return true;
  540. }
  541. return false;
  542. }
  543. bool ChatHandler::HandleTaxiCheatCommand(const char* args)
  544. {
  545. if (!*args)
  546. return false;
  547. int flag = atoi((char*)args);
  548. Player *chr = getSelectedPlayer();
  549. if (chr == NULL)
  550. {
  551. SendSysMessage(LANG_NO_CHAR_SELECTED);
  552. return true;
  553. }
  554. if (flag != 0)
  555. {
  556. chr->SetTaxiCheater(true);
  557. PSendSysMessage(LANG_YOU_GIVE_TAXIS, chr->GetName());
  558. if(chr != m_session->GetPlayer())
  559. {
  560. WorldPacket data;
  561. char buf[256];
  562. sprintf((char*)buf,LANG_YOURS_TAXIS_ADDED, m_session->GetPlayer()->GetName());
  563. FillSystemMessageData(&data, m_session, buf);
  564. chr->GetSession()->SendPacket(&data);
  565. }
  566. }
  567. else
  568. {
  569. chr->SetTaxiCheater(false);
  570. PSendSysMessage(LANG_YOU_REMOVE_TAXIS, chr->GetName());
  571. if(chr != m_session->GetPlayer())
  572. {
  573. WorldPacket data;
  574. char buf[256];
  575. sprintf((char*)buf,LANG_YOURS_TAXIS_REMOVED, m_session->GetPlayer()->GetName());
  576. FillSystemMessageData(&data, m_session, buf);
  577. chr->GetSession()->SendPacket(&data);
  578. }
  579. }
  580. return true;
  581. }
  582. bool ChatHandler::HandleModifyASpeedCommand(const char* args)
  583. {
  584. WorldPacket data;
  585. if (!*args)
  586. return false;
  587. float ASpeed = (float)atof((char*)args);
  588. if (ASpeed > 10 || ASpeed < 0.1)
  589. {
  590. SendSysMessage(LANG_BAD_VALUE);
  591. return true;
  592. }
  593. Player *chr = getSelectedPlayer();
  594. if (chr == NULL)
  595. {
  596. SendSysMessage(LANG_NO_CHAR_SELECTED);
  597. return true;
  598. }
  599. if(chr->isInFlight())
  600. {
  601. PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
  602. return true;
  603. }
  604. PSendSysMessage(LANG_YOU_CHANGE_ASPEED, ASpeed*100, chr->GetName());
  605. char buf[256];
  606. sprintf((char*)buf,LANG_YOURS_ASPEED_CHANGED, m_session->GetPlayer()->GetName(), ASpeed);
  607. FillSystemMessageData(&data, m_session, buf);
  608. chr->GetSession()->SendPacket(&data);
  609. chr->SetSpeed(MOVE_WALK, ASpeed,true);
  610. chr->SetSpeed(MOVE_RUN, ASpeed,true);
  611. chr->SetSpeed(MOVE_WALKBACK,ASpeed,true);
  612. chr->SetSpeed(MOVE_SWIM, ASpeed,true);
  613. chr->SetSpeed(MOVE_SWIMBACK,ASpeed,true);
  614. return true;
  615. }
  616. bool ChatHandler::HandleModifySpeedCommand(const char* args)
  617. {
  618. WorldPacket data;
  619. if (!*args)
  620. return false;
  621. float Speed = (float)atof((char*)args);
  622. if (Speed > 10 || Speed < 0.1)
  623. {
  624. SendSysMessage(LANG_BAD_VALUE);
  625. return true;
  626. }
  627. Player *chr = getSelectedPlayer();
  628. if (chr == NULL)
  629. {
  630. SendSysMessage(LANG_NO_CHAR_SELECTED);
  631. return true;
  632. }
  633. if(chr->isInFlight())
  634. {
  635. PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
  636. return true;
  637. }
  638. PSendSysMessage(LANG_YOU_CHANGE_SPEED, Speed, chr->GetName());
  639. char buf[256];
  640. sprintf((char*)buf,LANG_YOURS_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Speed);
  641. FillSystemMessageData(&data, m_session, buf);
  642. chr->GetSession()->SendPacket(&data);
  643. chr->SetSpeed(MOVE_RUN,Speed,true);
  644. return true;
  645. }
  646. bool ChatHandler::HandleModifySwimCommand(const char* args)
  647. {
  648. WorldPacket data;
  649. if (!*args)
  650. return false;
  651. float Swim = (float)atof((char*)args);
  652. if (Swim > 10 || Swim < 0.01)
  653. {
  654. SendSysMessage(LANG_BAD_VALUE);
  655. return true;
  656. }
  657. Player *chr = getSelectedPlayer();
  658. if (chr == NULL)
  659. {
  660. SendSysMessage(LANG_NO_CHAR_SELECTED);
  661. return true;
  662. }
  663. if(chr->isInFlight())
  664. {
  665. PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
  666. return true;
  667. }
  668. PSendSysMessage(LANG_YOU_CHANGE_SWIM_SPEED, Swim, chr->GetName());
  669. char buf[256];
  670. sprintf((char*)buf,LANG_YOURS_SWIM_SPEED_CHANGED, m_session->GetPlayer()->GetName(), Swim);
  671. FillSystemMessageData(&data, m_session, buf);
  672. chr->GetSession()->SendPacket(&data);
  673. chr->SetSpeed(MOVE_SWIM,Swim,true);
  674. return true;
  675. }
  676. bool ChatHandler::HandleModifyBWalkCommand(const char* args)
  677. {
  678. WorldPacket data;
  679. if (!*args)
  680. return false;
  681. float BSpeed = (float)atof((char*)args);
  682. if (BSpeed > 10 || BSpeed < 0.1)
  683. {
  684. SendSysMessage(LANG_BAD_VALUE);
  685. return true;
  686. }
  687. Player *chr = getSelectedPlayer();
  688. if (chr == NULL)
  689. {
  690. SendSysMessage(LANG_NO_CHAR_SELECTED);
  691. return true;
  692. }
  693. if(chr->isInFlight())
  694. {
  695. PSendSysMessage(LANG_CHAR_IN_FLIGHT,chr->GetName());
  696. return true;
  697. }
  698. PSendSysMessage(LANG_YOU_CHANGE_BACK_SPEED, BSpeed, chr->GetName());
  699. char buf[256];
  700. sprintf((char*)buf,LANG_YOURS_BACK_SPEED_CHANGED, m_session->GetPlayer()->GetName(), BSpeed);
  701. FillSystemMessageData(&data, m_session, buf);
  702. chr->GetSession()->SendPacket(&data);
  703. chr->SetSpeed(MOVE_WALKBACK,BSpeed,true);
  704. return true;
  705. }
  706. bool ChatHandler::HandleModifyScaleCommand(const char* args)
  707. {
  708. WorldPacket data;
  709. if (!*args)
  710. return false;
  711. float Scale = (float)atof((char*)args);
  712. if (Scale > 3 || Scale <= 0)
  713. {
  714. SendSysMessage(LANG_BAD_VALUE);
  715. return true;
  716. }
  717. Player *chr = getSelectedPlayer();
  718. if (chr == NULL)
  719. {
  720. SendSysMessage(LANG_NO_CHAR_SELECTED);
  721. return true;
  722. }
  723. PSendSysMessage(LANG_YOU_CHANGE_SIZE, Scale, chr->GetName());
  724. char buf[256];
  725. sprintf((char*)buf,LANG_YOURS_SIZE_CHANGED, m_session->GetPlayer()->GetName(), Scale);
  726. FillSystemMessageData(&data, m_session, buf);
  727. chr->GetSession()->SendPacket(&data);
  728. chr->SetFloatValue(OBJECT_FIELD_SCALE_X, Scale);
  729. return true;
  730. }
  731. bool ChatHandler::HandleModifyMountCommand(const char* args)
  732. {
  733. WorldPacket data;
  734. if(!*args)
  735. return false;
  736. uint16 mId = 1147;
  737. float speed = (float)15;
  738. uint32 num = 0;
  739. num = atoi((char*)args);
  740. switch(num)
  741. {
  742. case 1:
  743. mId=14340;
  744. break;
  745. case 2:
  746. mId=4806;
  747. break;
  748. case 3:
  749. mId=6471;
  750. break;
  751. case 4:
  752. mId=12345;
  753. break;
  754. case 5:
  755. mId=6472;
  756. break;
  757. case 6:
  758. mId=6473;
  759. break;
  760. case 7:
  761. mId=10670;
  762. break;
  763. case 8:
  764. mId=10719;
  765. break;
  766. case 9:
  767. mId=10671;
  768. break;
  769. case 10:
  770. mId=10672;
  771. break;
  772. case 11:
  773. mId=10720;
  774. break;
  775. case 12:
  776. mId=14349;
  777. break;
  778. case 13:
  779. mId=11641;
  780. break;
  781. case 14:
  782. mId=12244;
  783. break;
  784. case 15:
  785. mId=12242;
  786. break;
  787. case 16:
  788. mId=14578;
  789. break;
  790. case 17:
  791. mId=14579;
  792. break;
  793. case 18:
  794. mId=14349;
  795. break;
  796. case 19:
  797. mId=12245;
  798. break;
  799. case 20:
  800. mId=14335;
  801. break;
  802. case 21:
  803. mId=207;
  804. break;
  805. case 22:
  806. mId=2328;
  807. break;
  808. case 23:
  809. mId=2327;
  810. break;
  811. case 24:
  812. mId=2326;
  813. break;
  814. case 25:
  815. mId=14573;
  816. break;
  817. case 26:
  818. mId=14574;
  819. break;
  820. case 27:
  821. mId=14575;
  822. break;
  823. case 28:
  824. mId=604;
  825. break;
  826. case 29:
  827. mId=1166;
  828. break;
  829. case 30:
  830. mId=2402;
  831. break;
  832. case 31:
  833. mId=2410;
  834. break;
  835. case 32:
  836. mId=2409;
  837. break;
  838. case 33:
  839. mId=2408;
  840. break;
  841. case 34:
  842. mId=2405;
  843. break;
  844. case 35:
  845. mId=14337;
  846. break;
  847. case 36:
  848. mId=6569;
  849. break;
  850. case 37:
  851. mId=10661;
  852. break;
  853. case 38:
  854. mId=10666;
  855. break;
  856. case 39:
  857. mId=9473;
  858. break;
  859. case 40:
  860. mId=9476;
  861. break;
  862. case 41:
  863. mId=9474;
  864. break;
  865. case 42:
  866. mId=14374;
  867. break;
  868. case 43:
  869. mId=14376;
  870. break;
  871. case 44:
  872. mId=14377;
  873. break;
  874. case 45:
  875. mId=2404;
  876. break;
  877. case 46:
  878. mId=2784;
  879. break;
  880. case 47:
  881. mId=2787;
  882. break;
  883. case 48:
  884. mId=2785;
  885. break;
  886. case 49:
  887. mId=2736;
  888. break;
  889. case 50:
  890. mId=2786;
  891. break;
  892. case 51:
  893. mId=14347;
  894. break;
  895. case 52:
  896. mId=14346;
  897. break;
  898. case 53:
  899. mId=14576;
  900. break;
  901. case 54:
  902. mId=9695;
  903. break;
  904. case 55:
  905. mId=9991;
  906. break;
  907. case 56:
  908. mId=6448;
  909. break;
  910. case 57:
  911. mId=6444;
  912. break;
  913. case 58:
  914. mId=6080;
  915. break;
  916. case 59:
  917. mId=6447;
  918. break;
  919. case 60:
  920. mId=4805;
  921. break;
  922. case 61:
  923. mId=9714;
  924. break;
  925. case 62:
  926. mId=6448;
  927. break;
  928. case 63:
  929. mId=6442;
  930. break;
  931. case 64:
  932. mId=14632;
  933. break;
  934. case 65:
  935. mId=14332;
  936. break;
  937. case 66:
  938. mId=14331;
  939. break;
  940. case 67:
  941. mId=8469;
  942. break;
  943. case 68:
  944. mId=2830;
  945. break;
  946. case 69:
  947. mId=2346;
  948. break;
  949. default:
  950. SendSysMessage(LANG_NO_MOUNT);
  951. return true;
  952. }
  953. Player *chr = getSelectedPlayer();
  954. if (chr == NULL)
  955. {
  956. SendSysMessage(LANG_NO_CHAR_SELECTED);
  957. return true;
  958. }
  959. PSendSysMessage(LANG_YOU_GIVE_MOUNT, chr->GetName());
  960. char buf[256];
  961. sprintf((char*)buf,LANG_MOUNT_GIVED, m_session->GetPlayer()->GetName());
  962. FillSystemMessageData(&data, m_session, buf);
  963. chr->GetSession()->SendPacket(&data);
  964. chr->SetUInt32Value( UNIT_FIELD_FLAGS , 0x001000 );
  965. chr->Mount(mId);
  966. data.Initialize( SMSG_FORCE_RUN_SPEED_CHANGE, (8+4+4) );
  967. data.append(chr->GetPackGUID());
  968. data << (uint32)0;
  969. data << float(speed);
  970. chr->SendMessageToSet( &data, true );
  971. data.Initialize( SMSG_FORCE_SWIM_SPEED_CHANGE, (8+4+4) );
  972. data.append(chr->GetPackGUID());
  973. data << (uint32)0;
  974. data << float(speed);
  975. chr->SendMessageToSet( &data, true );
  976. return true;
  977. }
  978. bool ChatHandler::HandleModifyMoneyCommand(const char* args)
  979. {
  980. WorldPacket data;
  981. if (!*args)
  982. return false;
  983. Player *chr = getSelectedPlayer();
  984. if (chr == NULL)
  985. {
  986. SendSysMessage(LANG_NO_CHAR_SELECTED);
  987. return true;
  988. }
  989. int32 addmoney = atoi((char*)args);
  990. uint32 moneyuser = m_session->GetPlayer()->GetMoney();
  991. if(addmoney < 0)
  992. {
  993. int32 newmoney = moneyuser + addmoney;
  994. sLog.outDetail(LANG_CURRENT_MONEY, moneyuser, addmoney, newmoney);
  995. if(newmoney <= 0 )
  996. {
  997. PSendSysMessage(LANG_YOU_TAKE_ALL_MONEY, chr->GetName());
  998. char buf[256];
  999. sprintf((char*)buf,LANG_YOURS_ALL_MONEY_GONE, m_session->GetPlayer()->GetName());
  1000. FillSystemMessageData(&data, m_session, buf);
  1001. chr->GetSession()->SendPacket(&data);
  1002. chr->SetMoney(0);
  1003. }
  1004. else
  1005. {
  1006. PSendSysMessage(LANG_YOU_TAKE_MONEY, abs(addmoney), chr->GetName());
  1007. char buf[256];
  1008. sprintf((char*)buf,LANG_YOURS_MONEY_TAKEN, m_session->GetPlayer()->GetName(), abs(addmoney));
  1009. FillSystemMessageData(&data, m_session, buf);
  1010. chr->GetSession()->SendPacket(&data);
  1011. chr->SetMoney( newmoney );
  1012. }
  1013. }
  1014. else
  1015. {
  1016. PSendSysMessage(LANG_YOU_GIVE_MONEY, addmoney, chr->GetName());
  1017. char buf[256];
  1018. sprintf((char*)buf,LANG_YOURS_MONEY_GIVEN, m_session->GetPlayer()->GetName(), addmoney);
  1019. FillSystemMessageData(&data, m_session, buf);
  1020. chr->GetSession()->SendPacket(&data);
  1021. chr->ModifyMoney( addmoney );
  1022. }
  1023. sLog.outDetail(LANG_NEW_MONEY, moneyuser, addmoney, chr->GetMoney() );
  1024. return true;
  1025. }
  1026. bool ChatHandler::HandleModifyBitCommand(const char* args)
  1027. {
  1028. if( !*args )
  1029. return false;
  1030. Player *chr = getSelectedPlayer();
  1031. if (chr == NULL)
  1032. {
  1033. SendSysMessage(LANG_NO_CHAR_SELECTED);
  1034. return true;
  1035. }
  1036. char* pField = strtok((char*)args, " ");
  1037. if (!pField)
  1038. return false;
  1039. char* pBit = strtok(NULL, " ");
  1040. if (!pBit)
  1041. return false;
  1042. uint16 field = atoi(pField);
  1043. uint32 bit = atoi(pBit);
  1044. if (field < 1 || field >= PLAYER_END)
  1045. {
  1046. SendSysMessage(LANG_BAD_VALUE);
  1047. return true;
  1048. }
  1049. if (bit < 1 || bit > 32)
  1050. {
  1051. SendSysMessage(LANG_BAD_VALUE);
  1052. return true;
  1053. }
  1054. if ( chr->HasFlag( field, (1<<(bit-1)) ) )
  1055. {
  1056. chr->RemoveFlag( field, (1<<(bit-1)) );
  1057. PSendSysMessage(LANG_REMOVE_BIT, bit, field);
  1058. }
  1059. else
  1060. {
  1061. chr->SetFlag( field, (1<<(bit-1)) );
  1062. PSendSysMessage(LANG_SET_BIT, bit, field);
  1063. }
  1064. return true;
  1065. }
  1066. bool ChatHandler::HandleTeleCommand(const char * args)
  1067. {
  1068. Player* _player = m_session->GetPlayer();
  1069. if(_player->isInFlight())
  1070. {
  1071. SendSysMessage(LANG_YOU_IN_FLIGHT);
  1072. return true;
  1073. }
  1074. QueryResult *result;
  1075. if(!*args)
  1076. {
  1077. result = sDatabase.Query("SELECT `name` FROM `game_tele`");
  1078. if (!result)
  1079. {
  1080. SendSysMessage("Teleport location table is empty!");
  1081. return true;
  1082. }
  1083. std::string reply="Valid locations are:";
  1084. for (uint64 i=0; i < result->GetRowCount(); i++)
  1085. {
  1086. Field *fields = result->Fetch();
  1087. reply += " ";
  1088. reply += fields[0].GetCppString();
  1089. result->NextRow();
  1090. }
  1091. SendSysMessage(reply.c_str());
  1092. delete result;
  1093. return true;
  1094. }
  1095. std::string name = args;
  1096. sDatabase.escape_string(name);
  1097. result = sDatabase.PQuery("SELECT `position_x`,`position_y`,`position_z`,`orientation`,`map` FROM `game_tele` WHERE `name` = '%s'",name.c_str());
  1098. if (!result)
  1099. {
  1100. SendSysMessage("Teleport location not found!");
  1101. return true;
  1102. }
  1103. Field *fields = result->Fetch();
  1104. float x = fields[0].GetFloat();
  1105. float y = fields[1].GetFloat();
  1106. float z = fields[2].GetFloat();
  1107. float ort = fields[3].GetFloat();
  1108. int mapid = fields[4].GetUInt16();
  1109. delete result;
  1110. if(!MapManager::IsValidMapCoord(mapid,x,y))
  1111. {
  1112. PSendSysMessage(LANG_INVALID_TARGET_COORD,x,y,mapid);
  1113. return true;
  1114. }
  1115. _player->SetRecallPosition(_player->GetMapId(),_player->GetPositionX(),_player->GetPositionY(),_player->GetPositionZ(),_player->GetOrientation());
  1116. _player->TeleportTo(mapid, x, y, z, ort);
  1117. return true;
  1118. }
  1119. bool ChatHandler::HandleLookupTeleCommand(const char * args)
  1120. {
  1121. QueryResult *result;
  1122. if(!*args)
  1123. {
  1124. SendSysMessage("Requires search parameter.");
  1125. return true;
  1126. }
  1127. char const* str = strtok((char*)args, " ");
  1128. if(!str)
  1129. return false;
  1130. std::string namepart = str;
  1131. sDatabase.escape_string(namepart);
  1132. result = sDatabase.PQuery("SELECT `name` FROM `game_tele` WHERE `name` LIKE '%%%s%%'",namepart.c_str());
  1133. if (!result)
  1134. {
  1135. SendSysMessage("There are no teleport locations matching your request.");
  1136. return true;
  1137. }
  1138. std::string reply;
  1139. for (uint64 i=0; i < result->GetRowCount(); i++)
  1140. {
  1141. Field *fields = result->Fetch();
  1142. reply += " ";
  1143. reply += fields[0].GetCppString();
  1144. reply += '\n';
  1145. result->NextRow();
  1146. }
  1147. delete result;
  1148. if(reply.empty())
  1149. SendSysMessage("None locations found.");
  1150. else
  1151. {
  1152. reply = "Locations found are:\n" + reply;
  1153. SendSysMultilineMessage(reply.c_str());
  1154. }
  1155. return true;
  1156. }
  1157. bool ChatHandler::HandleWhispersCommand(const char* args)
  1158. {
  1159. char* px = strtok((char*)args, " ");
  1160. // ticket<end>
  1161. if (!px)
  1162. {
  1163. PSendSysMessage("Whispers accepting: %s", m_session->GetPlayer()->isAcceptWhispers() ? "on" : "off");
  1164. return true;
  1165. }
  1166. // ticket on
  1167. if(strncmp(px,"on",3) == 0)
  1168. {
  1169. m_session->GetPlayer()->SetAcceptWhispers(true);
  1170. SendSysMessage("Whispers accepting: on");
  1171. return true;
  1172. }
  1173. // ticket off
  1174. if(strncmp(px,"off",4) == 0)
  1175. {
  1176. m_session->GetPlayer()->SetAcceptWhispers(false);
  1177. SendSysMessage("Whispers accepting: off");
  1178. return true;
  1179. }
  1180. return false;
  1181. }
  1182. bool ChatHandler::HandlePlaySoundCommand(const char* args)
  1183. {
  1184. // USAGE: .playsound #soundid
  1185. // #soundid - ID decimal number from SoundEntries.dbc (1 column)
  1186. // this file have about 5000 sounds.
  1187. // In this realisation only caller can hear this sound.
  1188. if( *args )
  1189. {
  1190. int dwSoundId = atoi((char*)args);
  1191. if( dwSoundId >= 0 )
  1192. {
  1193. WorldPacket data;
  1194. data.Initialize(SMSG_PLAY_OBJECT_SOUND);
  1195. data << uint32(dwSoundId) << m_session->GetPlayer()->GetGUID();
  1196. m_session->SendPacket(&data);
  1197. sLog.outDebug("Player %s use command .playsound with #soundid=%u", m_session->GetPlayer()->GetName(), dwSoundId);
  1198. PSendSysMessage(LANG_YOU_HEAR_SOUND, dwSoundId);
  1199. return true;
  1200. }
  1201. }
  1202. SendSysMessage(LANG_BAD_VALUE);
  1203. return false;
  1204. }
  1205. bool ChatHandler::HandleSaveAllCommand(const char* args)
  1206. {
  1207. ObjectAccessor::Instance().SaveAllPlayers();
  1208. SendSysMessage(LANG_PLAYERS_SAVED);
  1209. return true;
  1210. }