AdminAdmin.java 16 KB

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