PageRenderTime 50ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/src/arcemu-world/Level0.cpp

http://wowtbc.googlecode.com/
C++ | 496 lines | 395 code | 71 blank | 30 comment | 107 complexity | f4ec5a25e335ab0f26299e56c8fe3c00 MD5 | raw file
Possible License(s): AGPL-3.0
  1. /*
  2. * ArcEmu MMORPG Server
  3. * Copyright (C) 2005-2007 Ascent Team <http://www.ascentemu.com/>
  4. * Copyright (C) 2008 <http://www.ArcEmu.org/>
  5. *
  6. * This program is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU Affero General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU Affero General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Affero General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. *
  19. */
  20. /////////////////////////////////////////////////
  21. // Normal User Chat Commands
  22. //
  23. #include "StdAfx.h"
  24. #include <svn_revision.h>
  25. bool ChatHandler::ShowHelpForCommand(WorldSession *m_session, ChatCommand *table, const char* cmd)
  26. {
  27. for(uint32 i = 0; table[i].Name != NULL; i++)
  28. {
  29. if(!hasStringAbbr(table[i].Name, cmd))
  30. continue;
  31. if(m_session->CanUseCommand(table[i].CommandGroup))
  32. continue;
  33. if(table[i].ChildCommands != NULL)
  34. {
  35. cmd = strtok(NULL, " ");
  36. if(cmd && ShowHelpForCommand(m_session, table[i].ChildCommands, cmd))
  37. return true;
  38. }
  39. if(table[i].Help == "")
  40. {
  41. SystemMessage(m_session, "There is no help for that command");
  42. return true;
  43. }
  44. SendMultilineMessage(m_session, table[i].Help.c_str());
  45. return true;
  46. }
  47. return false;
  48. }
  49. bool ChatHandler::HandleHelpCommand(const char* args, WorldSession *m_session)
  50. {
  51. // ChatCommand *table = getCommandTable();
  52. WorldPacket data;
  53. if(!*args)
  54. return false;
  55. char* cmd = strtok((char*)args, " ");
  56. if(!cmd)
  57. return false;
  58. if(!ShowHelpForCommand(m_session, CommandTableStorage::getSingleton().Get(), cmd))
  59. {
  60. RedSystemMessage(m_session, "Sorry, no help was found for this command, or that command does not exist.");
  61. }
  62. return true;
  63. }
  64. bool ChatHandler::HandleCommandsCommand(const char* args, WorldSession *m_session)
  65. {
  66. ChatCommand *table = CommandTableStorage::getSingleton().Get();
  67. WorldPacket data;
  68. std::string output;
  69. uint32 count = 0;
  70. output = "Available commands: \n\n";
  71. for(uint32 i = 0; table[i].Name != NULL; i++)
  72. {
  73. if(*args && !hasStringAbbr(table[i].Name, (char*)args))
  74. continue;
  75. if(table[i].CommandGroup != '0' && !m_session->CanUseCommand(table[i].CommandGroup))
  76. continue;
  77. switch(table[i].CommandGroup)
  78. {
  79. case 'z':
  80. {
  81. output+="|cffff6060";
  82. output+=table[i].Name;
  83. output+="|r, ";
  84. }
  85. break;
  86. case 'm':
  87. {
  88. output+="|cff00ffff";
  89. output+=table[i].Name;
  90. output+=", ";
  91. }
  92. break;
  93. case 'c':
  94. {
  95. output += "|cff00ff00";
  96. output += table[i].Name;
  97. output += "|r, ";
  98. }break;
  99. default:
  100. {
  101. output+="|cff00ccff";
  102. output+=table[i].Name;
  103. output+="|r, ";
  104. }
  105. break;
  106. }
  107. count++;
  108. if(count == 5) // 5 per line
  109. {
  110. output += "\n";
  111. count = 0;
  112. }
  113. }
  114. if(count)
  115. output += "\n";
  116. //FillSystemMessageData(&data, table[i].Name);
  117. //m_session->SendPacket(&data);
  118. //}
  119. SendMultilineMessage(m_session, output.c_str());
  120. return true;
  121. }
  122. bool ChatHandler::HandleStartCommand(const char* args, WorldSession *m_session)
  123. {
  124. std::string race;
  125. uint32 raceid = 0;
  126. Player *m_plyr = getSelectedChar(m_session, false);
  127. if (m_plyr && args && strlen(args) < 2)
  128. {
  129. raceid = m_plyr->getRace();
  130. switch (raceid)
  131. {
  132. case 1:
  133. race = "human";
  134. break;
  135. case 2:
  136. race = "orc";
  137. break;
  138. case 3:
  139. race = "dwarf";
  140. break;
  141. case 4:
  142. race = "nightelf";
  143. break;
  144. case 5:
  145. race = "undead";
  146. break;
  147. case 6:
  148. race = "tauren";
  149. break;
  150. case 7:
  151. race = "gnome";
  152. break;
  153. case 8:
  154. race = "troll";
  155. break;
  156. case 10:
  157. race = "bloodelf";
  158. break;
  159. case 11:
  160. race = "draenei";
  161. break;
  162. default:
  163. return false;
  164. break;
  165. }
  166. }
  167. else if (m_plyr && args && strlen(args) > 2)
  168. {
  169. race = args;
  170. arcemu_TOLOWER(race);
  171. // Teleport to specific race
  172. if(race == "human")
  173. raceid = 1;
  174. else if(race == "orc")
  175. raceid = 2;
  176. else if(race == "dwarf")
  177. raceid = 3;
  178. else if(race == "nightelf")
  179. raceid = 4;
  180. else if(race == "undead")
  181. raceid = 5;
  182. else if(race == "tauren")
  183. raceid = 6;
  184. else if(race == "gnome")
  185. raceid = 7;
  186. else if(race == "troll")
  187. raceid = 8;
  188. else if(race == "bloodelf")
  189. raceid = 10;
  190. else if(race == "draenei")
  191. raceid = 11;
  192. else
  193. {
  194. RedSystemMessage(m_session, "Invalid start location! Valid locations are: human, dwarf, gnome, nightelf, draenei, orc, troll, tauren, undead, bloodelf");
  195. return true;
  196. }
  197. }
  198. else
  199. {
  200. return false;
  201. }
  202. // Try to find a class that works
  203. PlayerCreateInfo *info = NULL;
  204. for(uint32 i=1;i<11;i++)
  205. {
  206. info = objmgr.GetPlayerCreateInfo(raceid, i);
  207. if(info != NULL) break;
  208. }
  209. if(info == NULL)
  210. {
  211. RedSystemMessage(m_session, "Internal error: Could not find create info.");
  212. return false;
  213. }
  214. GreenSystemMessage(m_session, "Telporting %s to %s starting location.", m_plyr->GetName(), race.c_str());
  215. m_plyr->SafeTeleport(info->mapId, 0, LocationVector(info->positionX, info->positionY, info->positionZ));
  216. return true;
  217. }
  218. bool ChatHandler::HandleInfoCommand(const char* args, WorldSession *m_session)
  219. {
  220. WorldPacket data;
  221. uint32 clientsNum = (uint32)sWorld.GetSessionCount();
  222. int gm = 0;
  223. int count = 0;
  224. int avg = 0;
  225. PlayerStorageMap::const_iterator itr;
  226. objmgr._playerslock.AcquireReadLock();
  227. for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++)
  228. {
  229. if(itr->second->GetSession())
  230. {
  231. count++;
  232. avg += itr->second->GetSession()->GetLatency();
  233. if(itr->second->GetSession()->GetPermissionCount())
  234. gm++;
  235. }
  236. }
  237. objmgr._playerslock.ReleaseReadLock();
  238. GreenSystemMessage(m_session, "Server Revision: |r%sArcEmu r%u/%s-%s-%s %s(www.arcemu.org)", MSG_COLOR_WHITE,
  239. BUILD_REVISION, CONFIG, PLATFORM_TEXT, ARCH, MSG_COLOR_LIGHTBLUE);
  240. GreenSystemMessage(m_session, "Server Uptime: |r%s", sWorld.GetUptimeString().c_str());
  241. GreenSystemMessage(m_session, "Current Players: |r%d (%d GMs, %d queued)", clientsNum, gm, 0);
  242. GreenSystemMessage(m_session, "Active Thread Count: |r%u", ThreadPool.GetActiveThreadCount());
  243. GreenSystemMessage(m_session, "Free Thread Count: |r%u", ThreadPool.GetFreeThreadCount());
  244. GreenSystemMessage(m_session, "Average Latency: |r%.3fms", (float)((float)avg / (float)count));
  245. GreenSystemMessage(m_session, "SQL Query Cache Size (World): |r%u queries delayed", WorldDatabase.GetQueueSize());
  246. GreenSystemMessage(m_session, "SQL Query Cache Size (Character): |r%u queries delayed", CharacterDatabase.GetQueueSize());
  247. return true;
  248. }
  249. bool ChatHandler::HandleNetworkStatusCommand(const char* args, WorldSession *m_session)
  250. {
  251. sSocketMgr.ShowStatus();
  252. return true;
  253. }
  254. bool ChatHandler::HandleNYICommand(const char* args, WorldSession *m_session)
  255. {
  256. RedSystemMessage(m_session, "Not yet implemented.");
  257. return true;
  258. }
  259. bool ChatHandler::HandleDismountCommand(const char* args, WorldSession *m_session)
  260. {
  261. Unit *m_target = NULL;
  262. Player *p_target = getSelectedChar(m_session, false);
  263. if(p_target)
  264. m_target = p_target;
  265. else
  266. {
  267. Creature *m_crt = getSelectedCreature(m_session, false);
  268. if(m_crt)
  269. m_target = m_crt;
  270. }
  271. if(!m_target)
  272. {
  273. RedSystemMessage(m_session, "No target found.");
  274. return true;
  275. }
  276. if(m_target->GetUInt32Value(UNIT_FIELD_MOUNTDISPLAYID) == 0)
  277. {
  278. RedSystemMessage(m_session, "Target is not mounted.");
  279. return true;
  280. }
  281. if(p_target && p_target->m_MountSpellId)
  282. p_target->RemoveAura(p_target->m_MountSpellId);
  283. m_target->SetUInt32Value( UNIT_FIELD_MOUNTDISPLAYID , 0);
  284. //m_target->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_MOUNTED_TAXI);
  285. BlueSystemMessage(m_session, "Now unmounted.");
  286. return true;
  287. }
  288. bool ChatHandler::HandleSaveCommand(const char* args, WorldSession *m_session)
  289. {
  290. Player *p_target = getSelectedChar(m_session, false);
  291. if(!p_target || !p_target->IsPlayer())
  292. return false;
  293. if(p_target && p_target->m_nextSave < 300000 ) //5min out of 10 left so 5 min since last save
  294. {
  295. p_target->SaveToDB(false);
  296. GreenSystemMessage(m_session, "Player %s saved to DB", p_target->GetName());
  297. }
  298. else
  299. {
  300. RedSystemMessage(m_session, "You can only save once every 5 minutes.");
  301. }
  302. return true;
  303. }
  304. bool ChatHandler::HandleGMListCommand(const char* args, WorldSession *m_session)
  305. {
  306. WorldPacket data;
  307. bool first = true;
  308. bool isGM = m_session->GetPermissionCount() != 0;
  309. PlayerStorageMap::const_iterator itr;
  310. objmgr._playerslock.AcquireReadLock();
  311. for (itr = objmgr._players.begin(); itr != objmgr._players.end(); itr++)
  312. {
  313. if(itr->second->GetSession()->GetPermissionCount())
  314. {
  315. if(isGM || !sWorld.gamemaster_listOnlyActiveGMs || (sWorld.gamemaster_listOnlyActiveGMs && itr->second->bGMTagOn))
  316. {
  317. if(first)
  318. GreenSystemMessage(m_session, "There are following active GMs on this server:");
  319. if(sWorld.gamemaster_hidePermissions && !isGM)
  320. SystemMessage(m_session, " - %s", itr->second->GetName());
  321. else
  322. {
  323. if(sWorld.gamemaster_listOnlyActiveGMs && !itr->second->bGMTagOn)
  324. SystemMessage(m_session, "|cff888888 - %s [%s]|r", itr->second->GetName(), itr->second->GetSession()->GetPermissions());
  325. else
  326. SystemMessage(m_session, " - %s [%s]", itr->second->GetName(), itr->second->GetSession()->GetPermissions());
  327. }
  328. first = false;
  329. }
  330. }
  331. }
  332. objmgr._playerslock.ReleaseReadLock();
  333. if(first)
  334. SystemMessage(m_session, "There are no GMs currently logged in on this server.");
  335. return true;
  336. }
  337. bool ChatHandler::HandleRangeCheckCommand( const char *args , WorldSession *m_session )
  338. {
  339. WorldPacket data;
  340. uint64 guid = m_session->GetPlayer()->GetSelection();
  341. m_session->SystemMessage( "=== RANGE CHECK ===" );
  342. if (guid == 0)
  343. {
  344. m_session->SystemMessage("No selection.");
  345. return true;
  346. }
  347. Unit *unit = m_session->GetPlayer()->GetMapMgr()->GetUnit( guid );
  348. if(!unit)
  349. {
  350. m_session->SystemMessage("Invalid selection.");
  351. return true;
  352. }
  353. float DistSq = unit->GetDistanceSq( static_cast<Object*>(m_session->GetPlayer()) );
  354. m_session->SystemMessage( "GetDistanceSq : %u" , FL2UINT( DistSq ) );
  355. LocationVector locvec( m_session->GetPlayer()->GetPositionX() , m_session->GetPlayer()->GetPositionY() , m_session->GetPlayer()->GetPositionZ() );
  356. float DistReal = unit->CalcDistance( locvec );
  357. m_session->SystemMessage( "CalcDistance : %u" , FL2UINT( DistReal ) );
  358. float Dist2DSq = unit->GetDistance2dSq( static_cast<Object*>(m_session->GetPlayer()) );
  359. m_session->SystemMessage( "GetDistance2dSq: %u" , FL2UINT( Dist2DSq ) );
  360. return true;
  361. }
  362. bool ChatHandler::HandleGmLogCommentCommand( const char *args , WorldSession *m_session )
  363. {
  364. if(!args || !strlen(args)) return false;
  365. BlueSystemMessage(m_session, "Added Logcomment: %s",args);
  366. sGMLog.writefromsession(m_session,"Logcomment: %s", args);
  367. return true;
  368. }
  369. bool ChatHandler::HandleRatingsCommand( const char *args , WorldSession *m_session )
  370. {
  371. m_session->SystemMessage("Ratings!!!");
  372. Player* m_plyr = getSelectedChar(m_session, false);
  373. for( uint32 i = 0; i < 24; i++ )
  374. {
  375. m_plyr->ModUnsigned32Value( PLAYER_FIELD_COMBAT_RATING_1 + i, i );
  376. }
  377. m_plyr->UpdateStats();
  378. return true;
  379. }
  380. bool ChatHandler::HandleStopXP(const char* args, WorldSession *m_session)
  381. {
  382. Player * pPlr = NULL;
  383. bool bGM = m_session->HasGMPermissions();
  384. //enable GMs to stopXP on someone else
  385. if(bGM)
  386. {
  387. Player * pPlr = getSelectedChar(m_session, true);
  388. if(!pPlr)
  389. {
  390. pPlr = m_session->GetPlayer();
  391. SystemMessage(m_session, "Auto-targeting self.");
  392. }
  393. }
  394. if(!pPlr)
  395. pPlr = m_session->GetPlayer();
  396. if(!pPlr)
  397. return false;
  398. if(!pPlr->m_stopXP)
  399. {
  400. pPlr->m_stopXP = true;
  401. if(bGM)
  402. {
  403. sGMLog.writefromsession(m_session, "disabled XP gaining for player %s", pPlr->GetName());
  404. BlueSystemMessageToPlr(pPlr, "%s disabled XP gaining on you.", m_session->GetPlayer()->GetName());
  405. GreenSystemMessage(m_session, "Disabled XP gaining on %s.", pPlr->GetName());
  406. return true;
  407. }
  408. BlueSystemMessage(m_session, "Experience gaining is now OFF.");
  409. BlueSystemMessage(m_session, "It will turn ON after using .StopXP again or logging out.");
  410. return true;
  411. }
  412. else
  413. {
  414. pPlr->m_stopXP = false;
  415. if(bGM)
  416. {
  417. sGMLog.writefromsession(m_session, "enabled XP gaining for player %s", pPlr->GetName());
  418. BlueSystemMessageToPlr(pPlr, "%s enabled XP gaining on you.", m_session->GetPlayer()->GetName());
  419. GreenSystemMessage(m_session, "Enabled XP gaining on %s.", pPlr->GetName());
  420. return true;
  421. }
  422. BlueSystemMessage(m_session, "Experience gaining is now ON.");
  423. return true;
  424. }
  425. }