AdminAdmin.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441
  1. /*
  2. * Copyright (C) 2004-2013 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack 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 GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Level;
  22. import java.util.logging.Logger;
  23. import javolution.text.TextBuilder;
  24. import com.l2jserver.Config;
  25. import com.l2jserver.gameserver.cache.HtmCache;
  26. import com.l2jserver.gameserver.datatables.AdminTable;
  27. import com.l2jserver.gameserver.datatables.DoorTable;
  28. import com.l2jserver.gameserver.datatables.ItemTable;
  29. import com.l2jserver.gameserver.datatables.MultisellData;
  30. import com.l2jserver.gameserver.datatables.NpcTable;
  31. import com.l2jserver.gameserver.datatables.SkillTable;
  32. import com.l2jserver.gameserver.datatables.SpawnTable;
  33. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  34. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  35. import com.l2jserver.gameserver.instancemanager.QuestManager;
  36. import com.l2jserver.gameserver.model.L2Spawn;
  37. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  38. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  39. import com.l2jserver.gameserver.network.SystemMessageId;
  40. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  41. /**
  42. * This class handles following admin commands: - admin|admin1/admin2/admin3/admin4/admin5 = slots for the 5 starting admin menus - gmliston/gmlistoff = includes/excludes active character from /gmlist results - silence = toggles private messages acceptance mode - diet = toggles weight penalty mode -
  43. * tradeoff = toggles trade acceptance mode - reload = reloads specified component from multisell|skill|npc|htm|item - set/set_menu/set_mod = alters specified server setting - saveolymp = saves olympiad state manually - manualhero = cycles olympiad and calculate new heroes.
  44. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  45. */
  46. public class AdminAdmin implements IAdminCommandHandler
  47. {
  48. private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  49. private static final String[] ADMIN_COMMANDS =
  50. {
  51. "admin_admin",
  52. "admin_admin1",
  53. "admin_admin2",
  54. "admin_admin3",
  55. "admin_admin4",
  56. "admin_admin5",
  57. "admin_admin6",
  58. "admin_admin7",
  59. "admin_gmliston",
  60. "admin_gmlistoff",
  61. "admin_silence",
  62. "admin_diet",
  63. "admin_tradeoff",
  64. "admin_reload",
  65. "admin_set",
  66. "admin_set_mod",
  67. "admin_saveolymp",
  68. "admin_manualhero",
  69. "admin_sethero",
  70. "admin_endolympiad",
  71. "admin_setconfig",
  72. "admin_config_server",
  73. "admin_gmon"
  74. };
  75. @Override
  76. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  77. {
  78. if (command.startsWith("admin_admin"))
  79. {
  80. showMainPage(activeChar, command);
  81. }
  82. else if (command.equals("admin_config_server"))
  83. {
  84. showConfigPage(activeChar);
  85. }
  86. else if (command.startsWith("admin_gmliston"))
  87. {
  88. AdminTable.getInstance().showGm(activeChar);
  89. activeChar.sendMessage("Registered into gm list");
  90. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  91. }
  92. else if (command.startsWith("admin_gmlistoff"))
  93. {
  94. AdminTable.getInstance().hideGm(activeChar);
  95. activeChar.sendMessage("Removed from gm list");
  96. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  97. }
  98. else if (command.startsWith("admin_silence"))
  99. {
  100. if (activeChar.isSilenceMode()) // already in message refusal mode
  101. {
  102. activeChar.setSilenceMode(false);
  103. activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  104. }
  105. else
  106. {
  107. activeChar.setSilenceMode(true);
  108. activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE);
  109. }
  110. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  111. }
  112. else if (command.startsWith("admin_saveolymp"))
  113. {
  114. Olympiad.getInstance().saveOlympiadStatus();
  115. activeChar.sendMessage("olympiad system saved.");
  116. }
  117. else if (command.startsWith("admin_endolympiad"))
  118. {
  119. try
  120. {
  121. Olympiad.getInstance().manualSelectHeroes();
  122. }
  123. catch (Exception e)
  124. {
  125. _log.warning("An error occured while ending olympiad: " + e);
  126. }
  127. activeChar.sendMessage("Heroes formed.");
  128. }
  129. else if (command.startsWith("admin_manualhero") || command.startsWith("admin_sethero"))
  130. {
  131. if (activeChar.getTarget() == null)
  132. {
  133. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  134. return false;
  135. }
  136. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  137. target.setHero(!target.isHero());
  138. target.broadcastUserInfo();
  139. }
  140. else if (command.startsWith("admin_diet"))
  141. {
  142. try
  143. {
  144. StringTokenizer st = new StringTokenizer(command);
  145. st.nextToken();
  146. if (st.nextToken().equalsIgnoreCase("on"))
  147. {
  148. activeChar.setDietMode(true);
  149. activeChar.sendMessage("Diet mode on");
  150. }
  151. else if (st.nextToken().equalsIgnoreCase("off"))
  152. {
  153. activeChar.setDietMode(false);
  154. activeChar.sendMessage("Diet mode off");
  155. }
  156. }
  157. catch (Exception ex)
  158. {
  159. if (activeChar.getDietMode())
  160. {
  161. activeChar.setDietMode(false);
  162. activeChar.sendMessage("Diet mode off");
  163. }
  164. else
  165. {
  166. activeChar.setDietMode(true);
  167. activeChar.sendMessage("Diet mode on");
  168. }
  169. }
  170. finally
  171. {
  172. activeChar.refreshOverloaded();
  173. }
  174. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  175. }
  176. else if (command.startsWith("admin_tradeoff"))
  177. {
  178. try
  179. {
  180. String mode = command.substring(15);
  181. if (mode.equalsIgnoreCase("on"))
  182. {
  183. activeChar.setTradeRefusal(true);
  184. activeChar.sendMessage("Trade refusal enabled");
  185. }
  186. else if (mode.equalsIgnoreCase("off"))
  187. {
  188. activeChar.setTradeRefusal(false);
  189. activeChar.sendMessage("Trade refusal disabled");
  190. }
  191. }
  192. catch (Exception ex)
  193. {
  194. if (activeChar.getTradeRefusal())
  195. {
  196. activeChar.setTradeRefusal(false);
  197. activeChar.sendMessage("Trade refusal disabled");
  198. }
  199. else
  200. {
  201. activeChar.setTradeRefusal(true);
  202. activeChar.sendMessage("Trade refusal enabled");
  203. }
  204. }
  205. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  206. }
  207. else if (command.startsWith("admin_reload"))
  208. {
  209. StringTokenizer st = new StringTokenizer(command);
  210. st.nextToken();
  211. if (!st.hasMoreTokens())
  212. {
  213. activeChar.sendMessage("You need to specify a type to reload!");
  214. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  215. return false;
  216. }
  217. final String type = st.nextToken();
  218. try
  219. {
  220. if (type.equals("multisell"))
  221. {
  222. MultisellData.getInstance().load();
  223. activeChar.sendMessage("All Multisells have been reloaded");
  224. }
  225. else if (type.startsWith("teleport"))
  226. {
  227. TeleportLocationTable.getInstance().reloadAll();
  228. activeChar.sendMessage("Teleport Locations have been reloaded");
  229. }
  230. else if (type.startsWith("skill"))
  231. {
  232. SkillTable.getInstance().reload();
  233. activeChar.sendMessage("All Skills have been reloaded");
  234. }
  235. else if (type.startsWith("npcId"))
  236. {
  237. Integer npcId = Integer.parseInt(st.nextToken());
  238. if (npcId != null)
  239. {
  240. NpcTable.getInstance().reloadNpc(npcId);
  241. for (L2Spawn spawn : SpawnTable.getInstance().getSpawns(npcId))
  242. {
  243. if (spawn != null)
  244. {
  245. spawn.respawnNpc(spawn.getLastSpawn());
  246. }
  247. }
  248. activeChar.sendMessage("NPC " + npcId + " have been reloaded");
  249. }
  250. }
  251. else if (type.equals("npc"))
  252. {
  253. NpcTable.getInstance().reloadAllNpc();
  254. QuestManager.getInstance().reloadAllQuests();
  255. activeChar.sendMessage("All NPCs have been reloaded");
  256. }
  257. else if (type.startsWith("htm"))
  258. {
  259. HtmCache.getInstance().reload();
  260. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  261. }
  262. else if (type.startsWith("item"))
  263. {
  264. ItemTable.getInstance().reload();
  265. activeChar.sendMessage("Item Templates have been reloaded");
  266. }
  267. else if (type.startsWith("config"))
  268. {
  269. Config.load();
  270. activeChar.sendMessage("All Config Settings have been reloaded");
  271. }
  272. else if (type.startsWith("access"))
  273. {
  274. AdminTable.getInstance().load();
  275. activeChar.sendMessage("Access Rights have been reloaded");
  276. }
  277. else if (type.startsWith("quests"))
  278. {
  279. QuestManager.getInstance().reloadAllQuests();
  280. activeChar.sendMessage("All Quests have been reloaded.");
  281. }
  282. else if (type.startsWith("door"))
  283. {
  284. DoorTable.getInstance().load();
  285. activeChar.sendMessage("All Doors have been reloaded");
  286. }
  287. activeChar.sendMessage("WARNING: There are several known issues regarding this feature. Reloading server data during runtime is STRONGLY NOT RECOMMENDED for live servers, just for developing environments.");
  288. }
  289. catch (Exception e)
  290. {
  291. activeChar.sendMessage("An error occured while reloading " + type + " !");
  292. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  293. _log.log(Level.WARNING, "An error occured while reloading " + type + ": " + e, e);
  294. }
  295. }
  296. else if (command.startsWith("admin_setconfig"))
  297. {
  298. StringTokenizer st = new StringTokenizer(command);
  299. st.nextToken();
  300. try
  301. {
  302. String pName = st.nextToken();
  303. String pValue = st.nextToken();
  304. if (Config.setParameterValue(pName, pValue))
  305. {
  306. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  307. }
  308. else
  309. {
  310. activeChar.sendMessage("Invalid parameter!");
  311. }
  312. }
  313. catch (Exception e)
  314. {
  315. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  316. }
  317. finally
  318. {
  319. showConfigPage(activeChar);
  320. }
  321. }
  322. else if (command.startsWith("admin_set"))
  323. {
  324. StringTokenizer st = new StringTokenizer(command);
  325. String[] cmd = st.nextToken().split("_");
  326. try
  327. {
  328. String[] parameter = st.nextToken().split("=");
  329. String pName = parameter[0].trim();
  330. String pValue = parameter[1].trim();
  331. if (Config.setParameterValue(pName, pValue))
  332. {
  333. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  334. }
  335. else
  336. {
  337. activeChar.sendMessage("Invalid parameter!");
  338. }
  339. }
  340. catch (Exception e)
  341. {
  342. if (cmd.length == 2)
  343. {
  344. activeChar.sendMessage("Usage: //set parameter=value");
  345. }
  346. }
  347. finally
  348. {
  349. if (cmd.length == 3)
  350. {
  351. if (cmd[2].equalsIgnoreCase("mod"))
  352. {
  353. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  354. }
  355. }
  356. }
  357. }
  358. else if (command.startsWith("admin_gmon"))
  359. {
  360. // nothing
  361. }
  362. return true;
  363. }
  364. @Override
  365. public String[] getAdminCommandList()
  366. {
  367. return ADMIN_COMMANDS;
  368. }
  369. private void showMainPage(L2PcInstance activeChar, String command)
  370. {
  371. int mode = 0;
  372. String filename = null;
  373. try
  374. {
  375. mode = Integer.parseInt(command.substring(11));
  376. }
  377. catch (Exception e)
  378. {
  379. }
  380. switch (mode)
  381. {
  382. case 1:
  383. filename = "main";
  384. break;
  385. case 2:
  386. filename = "game";
  387. break;
  388. case 3:
  389. filename = "effects";
  390. break;
  391. case 4:
  392. filename = "server";
  393. break;
  394. case 5:
  395. filename = "mods";
  396. break;
  397. case 6:
  398. filename = "char";
  399. break;
  400. case 7:
  401. filename = "gm";
  402. break;
  403. default:
  404. filename = "main";
  405. break;
  406. }
  407. AdminHelpPage.showHelpPage(activeChar, filename + "_menu.htm");
  408. }
  409. public void showConfigPage(L2PcInstance activeChar)
  410. {
  411. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  412. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  413. replyMSG.append("<center><table width=270><tr><td width=60><button value=\"Main\" action=\"bypass -h admin_admin\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td><td width=150>Config Server Panel</td><td width=60><button value=\"Back\" action=\"bypass -h admin_admin4\" width=60 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr></table></center><br>");
  414. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  415. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  416. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate EXP</font> = " + Config.RATE_XP + "</td><td><edit var=\"param1\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig RateXp $param1\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  417. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate SP</font> = " + Config.RATE_SP + "</td><td><edit var=\"param2\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig RateSp $param2\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  418. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate Drop Spoil</font> = " + Config.RATE_DROP_SPOIL + "</td><td><edit var=\"param4\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig RateDropSpoil $param4\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  419. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  420. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  421. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Stone</font> = " + Config.ENCHANT_CHANCE_ELEMENT_STONE + "</td><td><edit var=\"param8\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig EnchantChanceElementStone $param8\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  422. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Crystal</font> = " + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL + "</td><td><edit var=\"param9\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig EnchantChanceElementCrystal $param9\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  423. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Jewel</font> = " + Config.ENCHANT_CHANCE_ELEMENT_JEWEL + "</td><td><edit var=\"param10\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig EnchantChanceElementJewel $param10\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  424. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Energy</font> = " + Config.ENCHANT_CHANCE_ELEMENT_ENERGY + "</td><td><edit var=\"param11\" width=40 height=15></td><td><button value=\"Set\" action=\"bypass -h admin_setconfig EnchantChanceElementEnergy $param11\" width=40 height=25 back=\"L2UI_ct1.button_df\" fore=\"L2UI_ct1.button_df\"></td></tr>");
  425. replyMSG.append("</table></body></html>");
  426. adminReply.setHtml(replyMSG.toString());
  427. activeChar.sendPacket(adminReply);
  428. }
  429. }