AdminAdmin.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.io.File;
  21. import java.util.StringTokenizer;
  22. import java.util.logging.Level;
  23. import java.util.logging.Logger;
  24. import javax.script.ScriptException;
  25. import javolution.text.TextBuilder;
  26. import com.l2jserver.Config;
  27. import com.l2jserver.gameserver.cache.HtmCache;
  28. import com.l2jserver.gameserver.datatables.AdminTable;
  29. import com.l2jserver.gameserver.datatables.BuyListData;
  30. import com.l2jserver.gameserver.datatables.DoorTable;
  31. import com.l2jserver.gameserver.datatables.ItemTable;
  32. import com.l2jserver.gameserver.datatables.MultisellData;
  33. import com.l2jserver.gameserver.datatables.NpcTable;
  34. import com.l2jserver.gameserver.datatables.SkillTable;
  35. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  36. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  37. import com.l2jserver.gameserver.instancemanager.QuestManager;
  38. import com.l2jserver.gameserver.instancemanager.WalkingManager;
  39. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  40. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  41. import com.l2jserver.gameserver.network.SystemMessageId;
  42. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  43. import com.l2jserver.gameserver.scripting.L2ScriptEngineManager;
  44. /**
  45. * 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 -
  46. * 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.
  47. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  48. */
  49. public class AdminAdmin implements IAdminCommandHandler
  50. {
  51. private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  52. private static final String[] ADMIN_COMMANDS =
  53. {
  54. "admin_admin",
  55. "admin_admin1",
  56. "admin_admin2",
  57. "admin_admin3",
  58. "admin_admin4",
  59. "admin_admin5",
  60. "admin_admin6",
  61. "admin_admin7",
  62. "admin_gmliston",
  63. "admin_gmlistoff",
  64. "admin_silence",
  65. "admin_diet",
  66. "admin_tradeoff",
  67. "admin_reload",
  68. "admin_set",
  69. "admin_set_mod",
  70. "admin_saveolymp",
  71. "admin_manualhero",
  72. "admin_sethero",
  73. "admin_endolympiad",
  74. "admin_setconfig",
  75. "admin_config_server",
  76. "admin_gmon"
  77. };
  78. @Override
  79. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  80. {
  81. if (command.startsWith("admin_admin"))
  82. {
  83. showMainPage(activeChar, command);
  84. }
  85. else if (command.equals("admin_config_server"))
  86. {
  87. showConfigPage(activeChar);
  88. }
  89. else if (command.startsWith("admin_gmliston"))
  90. {
  91. AdminTable.getInstance().showGm(activeChar);
  92. activeChar.sendMessage("Registered into gm list");
  93. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  94. }
  95. else if (command.startsWith("admin_gmlistoff"))
  96. {
  97. AdminTable.getInstance().hideGm(activeChar);
  98. activeChar.sendMessage("Removed from gm list");
  99. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  100. }
  101. else if (command.startsWith("admin_silence"))
  102. {
  103. if (activeChar.isSilenceMode()) // already in message refusal mode
  104. {
  105. activeChar.setSilenceMode(false);
  106. activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  107. }
  108. else
  109. {
  110. activeChar.setSilenceMode(true);
  111. activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE);
  112. }
  113. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  114. }
  115. else if (command.startsWith("admin_saveolymp"))
  116. {
  117. Olympiad.getInstance().saveOlympiadStatus();
  118. activeChar.sendMessage("olympiad system saved.");
  119. }
  120. else if (command.startsWith("admin_endolympiad"))
  121. {
  122. try
  123. {
  124. Olympiad.getInstance().manualSelectHeroes();
  125. }
  126. catch (Exception e)
  127. {
  128. _log.warning("An error occured while ending olympiad: " + e);
  129. }
  130. activeChar.sendMessage("Heroes formed.");
  131. }
  132. else if (command.startsWith("admin_manualhero") || command.startsWith("admin_sethero"))
  133. {
  134. if (activeChar.getTarget() == null)
  135. {
  136. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  137. return false;
  138. }
  139. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  140. target.setHero(!target.isHero());
  141. target.broadcastUserInfo();
  142. }
  143. else if (command.startsWith("admin_diet"))
  144. {
  145. try
  146. {
  147. StringTokenizer st = new StringTokenizer(command);
  148. st.nextToken();
  149. if (st.nextToken().equalsIgnoreCase("on"))
  150. {
  151. activeChar.setDietMode(true);
  152. activeChar.sendMessage("Diet mode on");
  153. }
  154. else if (st.nextToken().equalsIgnoreCase("off"))
  155. {
  156. activeChar.setDietMode(false);
  157. activeChar.sendMessage("Diet mode off");
  158. }
  159. }
  160. catch (Exception ex)
  161. {
  162. if (activeChar.getDietMode())
  163. {
  164. activeChar.setDietMode(false);
  165. activeChar.sendMessage("Diet mode off");
  166. }
  167. else
  168. {
  169. activeChar.setDietMode(true);
  170. activeChar.sendMessage("Diet mode on");
  171. }
  172. }
  173. finally
  174. {
  175. activeChar.refreshOverloaded();
  176. }
  177. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  178. }
  179. else if (command.startsWith("admin_tradeoff"))
  180. {
  181. try
  182. {
  183. String mode = command.substring(15);
  184. if (mode.equalsIgnoreCase("on"))
  185. {
  186. activeChar.setTradeRefusal(true);
  187. activeChar.sendMessage("Trade refusal enabled");
  188. }
  189. else if (mode.equalsIgnoreCase("off"))
  190. {
  191. activeChar.setTradeRefusal(false);
  192. activeChar.sendMessage("Trade refusal disabled");
  193. }
  194. }
  195. catch (Exception ex)
  196. {
  197. if (activeChar.getTradeRefusal())
  198. {
  199. activeChar.setTradeRefusal(false);
  200. activeChar.sendMessage("Trade refusal disabled");
  201. }
  202. else
  203. {
  204. activeChar.setTradeRefusal(true);
  205. activeChar.sendMessage("Trade refusal enabled");
  206. }
  207. }
  208. AdminHelpPage.showHelpPage(activeChar, "gm_menu.htm");
  209. }
  210. else if (command.startsWith("admin_reload"))
  211. {
  212. StringTokenizer st = new StringTokenizer(command);
  213. st.nextToken();
  214. if (!st.hasMoreTokens())
  215. {
  216. activeChar.sendMessage("You need to specify a type to reload!");
  217. activeChar.sendMessage("Usage: //reload <multisell|buylist|teleport|skill|npc|htm|item|config|access|quests|door|walker|handler>");
  218. return false;
  219. }
  220. final String type = st.nextToken();
  221. try
  222. {
  223. if (type.equals("multisell"))
  224. {
  225. MultisellData.getInstance().load();
  226. activeChar.sendMessage("All Multisells have been reloaded");
  227. }
  228. else if (type.startsWith("buylist"))
  229. {
  230. BuyListData.getInstance().load();
  231. activeChar.sendMessage("All BuyLists have been reloaded");
  232. }
  233. else if (type.startsWith("teleport"))
  234. {
  235. TeleportLocationTable.getInstance().reloadAll();
  236. activeChar.sendMessage("Teleport Locations have been reloaded");
  237. }
  238. else if (type.startsWith("skill"))
  239. {
  240. SkillTable.getInstance().reload();
  241. activeChar.sendMessage("All Skills have been reloaded");
  242. }
  243. else if (type.startsWith("npcId"))
  244. {
  245. Integer npcId = Integer.parseInt(st.nextToken());
  246. if (npcId != null)
  247. {
  248. NpcTable.getInstance().reloadNpc(npcId, true, true, true, true, true, true);
  249. activeChar.sendMessage("NPC " + npcId + " have been reloaded");
  250. }
  251. }
  252. else if (type.equals("npc"))
  253. {
  254. NpcTable.getInstance().reloadAllNpc();
  255. QuestManager.getInstance().reloadAllQuests();
  256. activeChar.sendMessage("All NPCs have been reloaded");
  257. }
  258. else if (type.startsWith("htm"))
  259. {
  260. HtmCache.getInstance().reload();
  261. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  262. }
  263. else if (type.startsWith("item"))
  264. {
  265. ItemTable.getInstance().reload();
  266. activeChar.sendMessage("Item Templates have been reloaded");
  267. }
  268. else if (type.startsWith("config"))
  269. {
  270. Config.load();
  271. activeChar.sendMessage("All Config Settings have been reloaded");
  272. }
  273. else if (type.startsWith("access"))
  274. {
  275. AdminTable.getInstance().load();
  276. activeChar.sendMessage("Access Rights have been reloaded");
  277. }
  278. else if (type.startsWith("quests"))
  279. {
  280. QuestManager.getInstance().reloadAllQuests();
  281. activeChar.sendMessage("All Quests have been reloaded.");
  282. }
  283. else if (type.startsWith("door"))
  284. {
  285. DoorTable.getInstance().load();
  286. activeChar.sendMessage("All Doors have been reloaded");
  287. }
  288. else if (type.startsWith("walker"))
  289. {
  290. WalkingManager.getInstance().load();
  291. activeChar.sendMessage("All Walkers have been reloaded");
  292. }
  293. else if (type.startsWith("handler"))
  294. {
  295. File file = new File(L2ScriptEngineManager.SCRIPT_FOLDER, "handlers/MasterHandler.java");
  296. try
  297. {
  298. L2ScriptEngineManager.getInstance().executeScript(file);
  299. activeChar.sendMessage("All handlers have been reloaded");
  300. }
  301. catch (ScriptException e)
  302. {
  303. L2ScriptEngineManager.getInstance().reportScriptFileError(file, e);
  304. activeChar.sendMessage("There was an error while loading handlers.");
  305. }
  306. }
  307. 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.");
  308. }
  309. catch (Exception e)
  310. {
  311. activeChar.sendMessage("An error occured while reloading " + type + " !");
  312. activeChar.sendMessage("Usage: //reload <multisell|buylist|teleport|skill|npc|htm|item|config|access|quests|door|walker|handler>");
  313. _log.log(Level.WARNING, "An error occured while reloading " + type + ": " + e, e);
  314. }
  315. }
  316. else if (command.startsWith("admin_setconfig"))
  317. {
  318. StringTokenizer st = new StringTokenizer(command);
  319. st.nextToken();
  320. try
  321. {
  322. String pName = st.nextToken();
  323. String pValue = st.nextToken();
  324. if (Config.setParameterValue(pName, pValue))
  325. {
  326. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  327. }
  328. else
  329. {
  330. activeChar.sendMessage("Invalid parameter!");
  331. }
  332. }
  333. catch (Exception e)
  334. {
  335. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  336. }
  337. finally
  338. {
  339. showConfigPage(activeChar);
  340. }
  341. }
  342. else if (command.startsWith("admin_set"))
  343. {
  344. StringTokenizer st = new StringTokenizer(command);
  345. String[] cmd = st.nextToken().split("_");
  346. try
  347. {
  348. String[] parameter = st.nextToken().split("=");
  349. String pName = parameter[0].trim();
  350. String pValue = parameter[1].trim();
  351. if (Config.setParameterValue(pName, pValue))
  352. {
  353. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  354. }
  355. else
  356. {
  357. activeChar.sendMessage("Invalid parameter!");
  358. }
  359. }
  360. catch (Exception e)
  361. {
  362. if (cmd.length == 2)
  363. {
  364. activeChar.sendMessage("Usage: //set parameter=value");
  365. }
  366. }
  367. finally
  368. {
  369. if (cmd.length == 3)
  370. {
  371. if (cmd[2].equalsIgnoreCase("mod"))
  372. {
  373. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  374. }
  375. }
  376. }
  377. }
  378. else if (command.startsWith("admin_gmon"))
  379. {
  380. // nothing
  381. }
  382. return true;
  383. }
  384. @Override
  385. public String[] getAdminCommandList()
  386. {
  387. return ADMIN_COMMANDS;
  388. }
  389. private void showMainPage(L2PcInstance activeChar, String command)
  390. {
  391. int mode = 0;
  392. String filename = null;
  393. try
  394. {
  395. mode = Integer.parseInt(command.substring(11));
  396. }
  397. catch (Exception e)
  398. {
  399. }
  400. switch (mode)
  401. {
  402. case 1:
  403. filename = "main";
  404. break;
  405. case 2:
  406. filename = "game";
  407. break;
  408. case 3:
  409. filename = "effects";
  410. break;
  411. case 4:
  412. filename = "server";
  413. break;
  414. case 5:
  415. filename = "mods";
  416. break;
  417. case 6:
  418. filename = "char";
  419. break;
  420. case 7:
  421. filename = "gm";
  422. break;
  423. default:
  424. filename = "main";
  425. break;
  426. }
  427. AdminHelpPage.showHelpPage(activeChar, filename + "_menu.htm");
  428. }
  429. public void showConfigPage(L2PcInstance activeChar)
  430. {
  431. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  432. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  433. 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>");
  434. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  435. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  436. 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>");
  437. 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>");
  438. 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>");
  439. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  440. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  441. 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>");
  442. 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>");
  443. 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>");
  444. 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>");
  445. replyMSG.append("</table></body></html>");
  446. adminReply.setHtml(replyMSG.toString());
  447. activeChar.sendPacket(adminReply);
  448. }
  449. }