PageRenderTime 42ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 1ms

/src/game/Level0.cpp

https://github.com/Archives/try
C++ | 353 lines | 280 code | 47 blank | 26 comment | 46 complexity | 00296d377929a232a3dc282a8bafe84c MD5 | raw file
  1. /*
  2. * Copyright (C) 2005-2010 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 "World.h"
  21. #include "Player.h"
  22. #include "Opcodes.h"
  23. #include "Chat.h"
  24. #include "ObjectAccessor.h"
  25. #include "Language.h"
  26. #include "AccountMgr.h"
  27. #include "SystemConfig.h"
  28. #include "revision.h"
  29. #include "revision_nr.h"
  30. #include "Util.h"
  31. #include "GameEventMgr.h"
  32. bool ChatHandler::HandleHelpCommand(const char* args)
  33. {
  34. char* cmd = strtok((char*)args, " ");
  35. if (!cmd)
  36. {
  37. ShowHelpForCommand(getCommandTable(), "help");
  38. ShowHelpForCommand(getCommandTable(), "");
  39. }
  40. else
  41. {
  42. if (!ShowHelpForCommand(getCommandTable(), cmd))
  43. SendSysMessage(LANG_NO_HELP_CMD);
  44. }
  45. return true;
  46. }
  47. bool ChatHandler::HandleCommandsCommand(const char* /*args*/)
  48. {
  49. ShowHelpForCommand(getCommandTable(), "");
  50. return true;
  51. }
  52. bool ChatHandler::HandleAccountCommand(const char* /*args*/)
  53. {
  54. AccountTypes gmlevel = GetAccessLevel();
  55. PSendSysMessage(LANG_ACCOUNT_LEVEL, uint32(gmlevel));
  56. return true;
  57. }
  58. bool ChatHandler::HandleStartCommand(const char* /*args*/)
  59. {
  60. Player *chr = m_session->GetPlayer();
  61. if (chr->isInFlight())
  62. {
  63. SendSysMessage(LANG_YOU_IN_FLIGHT);
  64. SetSentErrorMessage(true);
  65. return false;
  66. }
  67. if (chr->isInCombat())
  68. {
  69. SendSysMessage(LANG_YOU_IN_COMBAT);
  70. SetSentErrorMessage(true);
  71. return false;
  72. }
  73. // cast spell Stuck
  74. chr->CastSpell(chr,7355,false);
  75. return true;
  76. }
  77. bool ChatHandler::HandleServerInfoCommand(const char* /*args*/)
  78. {
  79. uint32 activeClientsNum = sWorld.GetActiveSessionCount();
  80. //uint32 queuedClientsNum = sWorld.GetQueuedSessionCount();
  81. uint32 maxActiveClientsNum = sWorld.GetMaxActiveSessionCount();
  82. //uint32 maxQueuedClientsNum = sWorld.GetMaxQueuedSessionCount();
  83. std::string str = secsToTimeString(sWorld.GetUptime());
  84. char const* valhalla_rev = REVISION_VP;
  85. char const* valhalla_rev_date = REVISION_VP_DATE;
  86. char const* full;
  87. if (m_session)
  88. full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,"|cffffffff|Hurl:" REVISION_ID "|h" REVISION_ID "|h|r");
  89. else
  90. full = _FULLVERSION(REVISION_DATE,REVISION_TIME,REVISION_NR,REVISION_ID);
  91. SendSysMessage(full);
  92. if (GetAccessLevel() > SEC_PLAYER)
  93. {
  94. PSendSysMessage(LANG_USING_SCRIPT_LIB,sWorld.GetScriptsVersion());
  95. PSendSysMessage(LANG_USING_WORLD_DB,sWorld.GetDBVersion());
  96. PSendSysMessage(LANG_USING_EVENT_AI,sWorld.GetCreatureEventAIVersion());
  97. }
  98. PSendSysMessage("CatCore [%s][%s] - MaNGOS modified for Valhalla Server", valhalla_rev, valhalla_rev_date);
  99. SendSysMessage("Changelog: http://valhalla-team.com/web/changelog.php");
  100. PSendSysMessage(LANG_CONNECTED_USERS, activeClientsNum, maxActiveClientsNum);
  101. PSendSysMessage(LANG_UPTIME, str.c_str());
  102. PSendSysMessage("World diff time: %u", sWorld.GetDiffTime());
  103. if (sWorld.IsShutdowning())
  104. {
  105. const char *type = (sWorld.GetShutdownMask() & SHUTDOWN_MASK_RESTART) ? "Restart" : "Shutdown";
  106. uint32 shutdownTimer = sWorld.GetShutdownTimer();
  107. if (shutdownTimer > 60*60) //Hours
  108. {
  109. uint8 hours = shutdownTimer / (60*60);
  110. uint8 mins = (shutdownTimer - hours*60*60) / 60;
  111. uint8 secs = (shutdownTimer - hours*60*60 - mins*60);
  112. PSendSysMessage("[SERVER] %s in %u hours, %u minutes and %u seconds", type, hours, mins, secs);
  113. }
  114. else if (shutdownTimer > 60) // Minutes
  115. {
  116. uint8 mins = shutdownTimer / 60;
  117. uint8 secs = (shutdownTimer - mins*60);
  118. PSendSysMessage("[SERVER] %s in %u minutes and %u seconds", type, mins, secs);
  119. }
  120. else //Only seconds
  121. PSendSysMessage("[SERVER] %s in %u seconds", type, shutdownTimer);
  122. }
  123. return true;
  124. }
  125. bool ChatHandler::HandleDismountCommand(const char* /*args*/)
  126. {
  127. //If player is not mounted, so go out :)
  128. if (!m_session->GetPlayer( )->IsMounted())
  129. {
  130. SendSysMessage(LANG_CHAR_NON_MOUNTED);
  131. SetSentErrorMessage(true);
  132. return false;
  133. }
  134. if (m_session->GetPlayer( )->isInFlight())
  135. {
  136. SendSysMessage(LANG_YOU_IN_FLIGHT);
  137. SetSentErrorMessage(true);
  138. return false;
  139. }
  140. m_session->GetPlayer()->Unmount();
  141. m_session->GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOUNTED);
  142. return true;
  143. }
  144. bool ChatHandler::HandleSaveCommand(const char* /*args*/)
  145. {
  146. Player *player=m_session->GetPlayer();
  147. // save GM account without delay and output message (testing, etc)
  148. if (GetAccessLevel() > SEC_PLAYER)
  149. {
  150. player->SaveToDB();
  151. SendSysMessage(LANG_PLAYER_SAVED);
  152. return true;
  153. }
  154. // save or plan save after 20 sec (logout delay) if current next save time more this value and _not_ output any messages to prevent cheat planning
  155. uint32 save_interval = sWorld.getConfig(CONFIG_UINT32_INTERVAL_SAVE);
  156. if (save_interval==0 || (save_interval > 20*IN_MILLISECONDS && player->GetSaveTimer() <= save_interval - 20*IN_MILLISECONDS))
  157. player->SaveToDB();
  158. return true;
  159. }
  160. bool ChatHandler::HandleGMListIngameCommand(const char* /*args*/)
  161. {
  162. std::list< std::pair<std::string, bool> > names;
  163. {
  164. HashMapHolder<Player>::ReadGuard g(HashMapHolder<Player>::GetLock());
  165. HashMapHolder<Player>::MapType &m = sObjectAccessor.GetPlayers();
  166. for(HashMapHolder<Player>::MapType::const_iterator itr = m.begin(); itr != m.end(); ++itr)
  167. {
  168. AccountTypes itr_sec = itr->second->GetSession()->GetSecurity();
  169. if ((itr->second->isGameMaster() || (itr_sec > SEC_PLAYER && itr_sec <= (AccountTypes)sWorld.getConfig(CONFIG_UINT32_GM_LEVEL_IN_GM_LIST))) &&
  170. (!m_session || itr->second->IsVisibleGloballyFor(m_session->GetPlayer())))
  171. names.push_back(std::make_pair<std::string, bool>(GetNameLink(itr->second), itr->second->isAcceptWhispers()));
  172. }
  173. }
  174. if (!names.empty())
  175. {
  176. SendSysMessage(LANG_GMS_ON_SRV);
  177. char const* accepts = GetMangosString(LANG_GM_ACCEPTS_WHISPER);
  178. char const* not_accept = GetMangosString(LANG_GM_NO_WHISPER);
  179. for(std::list<std::pair< std::string, bool> >::const_iterator iter = names.begin(); iter != names.end(); ++iter)
  180. PSendSysMessage("%s - %s", iter->first.c_str(), iter->second ? accepts : not_accept);
  181. }
  182. else
  183. SendSysMessage(LANG_GMS_NOT_LOGGED);
  184. return true;
  185. }
  186. bool ChatHandler::HandleAccountPasswordCommand(const char* args)
  187. {
  188. // allow use from RA, but not from console (not have associated account id)
  189. if (!GetAccountId())
  190. {
  191. SendSysMessage (LANG_RA_ONLY_COMMAND);
  192. SetSentErrorMessage (true);
  193. return false;
  194. }
  195. if (!*args)
  196. return false;
  197. char *old_pass = strtok ((char*)args, " ");
  198. char *new_pass = strtok (NULL, " ");
  199. char *new_pass_c = strtok (NULL, " ");
  200. if (!old_pass || !new_pass || !new_pass_c)
  201. return false;
  202. std::string password_old = old_pass;
  203. std::string password_new = new_pass;
  204. std::string password_new_c = new_pass_c;
  205. if (password_new != password_new_c)
  206. {
  207. SendSysMessage (LANG_NEW_PASSWORDS_NOT_MATCH);
  208. SetSentErrorMessage (true);
  209. return false;
  210. }
  211. if (!sAccountMgr.CheckPassword (GetAccountId(), password_old))
  212. {
  213. SendSysMessage (LANG_COMMAND_WRONGOLDPASSWORD);
  214. SetSentErrorMessage (true);
  215. return false;
  216. }
  217. AccountOpResult result = sAccountMgr.ChangePassword(GetAccountId(), password_new);
  218. switch(result)
  219. {
  220. case AOR_OK:
  221. SendSysMessage(LANG_COMMAND_PASSWORD);
  222. break;
  223. case AOR_PASS_TOO_LONG:
  224. SendSysMessage(LANG_PASSWORD_TOO_LONG);
  225. SetSentErrorMessage(true);
  226. return false;
  227. case AOR_NAME_NOT_EXIST: // not possible case, don't want get account name for output
  228. default:
  229. SendSysMessage(LANG_COMMAND_NOTCHANGEPASSWORD);
  230. SetSentErrorMessage(true);
  231. return false;
  232. }
  233. return true;
  234. }
  235. bool ChatHandler::HandleAccountLockCommand(const char* args)
  236. {
  237. // allow use from RA, but not from console (not have associated account id)
  238. if (!GetAccountId())
  239. {
  240. SendSysMessage (LANG_RA_ONLY_COMMAND);
  241. SetSentErrorMessage (true);
  242. return false;
  243. }
  244. if (!*args)
  245. {
  246. SendSysMessage(LANG_USE_BOL);
  247. return true;
  248. }
  249. std::string argstr = (char*)args;
  250. if (argstr == "on")
  251. {
  252. LoginDatabase.PExecute( "UPDATE account SET locked = '1' WHERE id = '%d'",GetAccountId());
  253. PSendSysMessage(LANG_COMMAND_ACCLOCKLOCKED);
  254. return true;
  255. }
  256. if (argstr == "off")
  257. {
  258. LoginDatabase.PExecute( "UPDATE account SET locked = '0' WHERE id = '%d'",GetAccountId());
  259. PSendSysMessage(LANG_COMMAND_ACCLOCKUNLOCKED);
  260. return true;
  261. }
  262. SendSysMessage(LANG_USE_BOL);
  263. return true;
  264. }
  265. /// Display the 'Message of the day' for the realm
  266. bool ChatHandler::HandleServerMotdCommand(const char* /*args*/)
  267. {
  268. PSendSysMessage(LANG_MOTD_CURRENT, sWorld.GetMotd());
  269. return true;
  270. }
  271. bool ChatHandler::HandleLitakCommand(const char* args)
  272. {
  273. std::string argstr = (char*)args;
  274. Player *player=m_session->GetPlayer();
  275. if (player->isInCombat())
  276. {
  277. SendSysMessage(LANG_YOU_IN_COMBAT);
  278. SetSentErrorMessage(true);
  279. return false;
  280. }
  281. if (player->isInFlight())
  282. player->Unmount();
  283. player->clearUnitState(UNIT_STAT_IN_FLIGHT);
  284. player->GetMotionMaster()->Clear(false, true);
  285. if (argstr == "textura")
  286. {
  287. if (!player->m_taxi.empty())
  288. {
  289. TaxiNodesEntry const* curSrcNode = sTaxiNodesStore.LookupEntry(player->m_taxi.GetTaxiSource());
  290. player->m_taxi.ClearTaxiDestinations();
  291. if (curSrcNode)
  292. player->TeleportTo(curSrcNode->map_id, curSrcNode->x, curSrcNode->y, curSrcNode->z, 0);
  293. else
  294. player->MonsterMove(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), 0);
  295. }
  296. else
  297. {
  298. player->m_taxi.ClearTaxiDestinations();
  299. player->MonsterMove(player->GetPositionX(), player->GetPositionY(), player->GetPositionZ(), 0);
  300. }
  301. }
  302. player->m_taxi.ClearTaxiDestinations();
  303. player->RemoveFlag(UNIT_FIELD_FLAGS,UNIT_FLAG_DISABLE_MOVE | UNIT_FLAG_TAXI_FLIGHT);
  304. player->StopMoving();
  305. return true;
  306. }