AdminAdmin.java 17 KB

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