AdminAdmin.java 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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.SpawnTable;
  31. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  32. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  33. import com.l2jserver.gameserver.instancemanager.Manager;
  34. import com.l2jserver.gameserver.instancemanager.QuestManager;
  35. import com.l2jserver.gameserver.model.L2Spawn;
  36. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  37. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  38. import com.l2jserver.gameserver.network.SystemMessageId;
  39. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  40. import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
  41. /**
  42. * This class handles following admin commands:
  43. * - admin|admin1/admin2/admin3/admin4/admin5 = slots for the 5 starting admin menus
  44. * - gmliston/gmlistoff = includes/excludes active character from /gmlist results
  45. * - silence = toggles private messages acceptance mode
  46. * - diet = toggles weight penalty mode
  47. * - tradeoff = toggles trade acceptance mode
  48. * - reload = reloads specified component from multisell|skill|npc|htm|item|instancemanager
  49. * - set/set_menu/set_mod = alters specified server setting
  50. * - saveolymp = saves olympiad state manually
  51. * - manualhero = cycles olympiad and calculate new heroes.
  52. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  53. */
  54. public class AdminAdmin implements IAdminCommandHandler
  55. {
  56. private static Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  57. private static final String[] ADMIN_COMMANDS =
  58. {
  59. "admin_admin",
  60. "admin_admin1",
  61. "admin_admin2",
  62. "admin_admin3",
  63. "admin_admin4",
  64. "admin_admin5",
  65. "admin_admin6",
  66. "admin_admin7",
  67. "admin_admin8",
  68. "admin_gmliston",
  69. "admin_gmlistoff",
  70. "admin_silence",
  71. "admin_diet",
  72. "admin_tradeoff",
  73. "admin_reload",
  74. "admin_set",
  75. "admin_set_mod",
  76. "admin_saveolymp",
  77. "admin_manualhero",
  78. "admin_sethero",
  79. "admin_endolympiad",
  80. "admin_setconfig",
  81. "admin_config_server",
  82. "admin_gmon"
  83. };
  84. @Override
  85. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  86. {
  87. if (command.startsWith("admin_admin"))
  88. {
  89. showMainPage(activeChar, command);
  90. }
  91. else if (command.equals("admin_config_server"))
  92. {
  93. showConfigPage(activeChar);
  94. }
  95. else if (command.startsWith("admin_gmliston"))
  96. {
  97. GmListTable.getInstance().showGm(activeChar);
  98. activeChar.sendMessage("Registered into gm list");
  99. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  100. }
  101. else if (command.startsWith("admin_gmlistoff"))
  102. {
  103. GmListTable.getInstance().hideGm(activeChar);
  104. activeChar.sendMessage("Removed from gm list");
  105. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  106. }
  107. else if (command.startsWith("admin_silence"))
  108. {
  109. if (activeChar.isSilenceMode()) // already in message refusal mode
  110. {
  111. activeChar.setSilenceMode(false);
  112. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MESSAGE_ACCEPTANCE_MODE));
  113. }
  114. else
  115. {
  116. activeChar.setSilenceMode(true);
  117. activeChar.sendPacket(SystemMessage.getSystemMessage(SystemMessageId.MESSAGE_REFUSAL_MODE));
  118. }
  119. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  120. }
  121. else if (command.startsWith("admin_saveolymp"))
  122. {
  123. Olympiad.getInstance().saveOlympiadStatus();
  124. activeChar.sendMessage("olympiad system saved.");
  125. }
  126. else if (command.startsWith("admin_endolympiad"))
  127. {
  128. try
  129. {
  130. Olympiad.getInstance().manualSelectHeroes();
  131. }
  132. catch (Exception e)
  133. {
  134. _log.warning("An error occured while ending olympiad: " + e);
  135. }
  136. activeChar.sendMessage("Heroes formed");
  137. }
  138. else if (command.startsWith("admin_manualhero") || command.startsWith("admin_sethero"))
  139. {
  140. L2PcInstance target = null;
  141. if (activeChar.getTarget() instanceof L2PcInstance)
  142. {
  143. target = (L2PcInstance) activeChar.getTarget();
  144. target.setHero(target.isHero() ? false : true);
  145. }
  146. else
  147. {
  148. target = activeChar;
  149. target.setHero(target.isHero() ? false : true);
  150. }
  151. target.broadcastUserInfo();
  152. }
  153. else if (command.startsWith("admin_diet"))
  154. {
  155. try
  156. {
  157. StringTokenizer st = new StringTokenizer(command);
  158. st.nextToken();
  159. if (st.nextToken().equalsIgnoreCase("on"))
  160. {
  161. activeChar.setDietMode(true);
  162. activeChar.sendMessage("Diet mode on");
  163. }
  164. else if (st.nextToken().equalsIgnoreCase("off"))
  165. {
  166. activeChar.setDietMode(false);
  167. activeChar.sendMessage("Diet mode off");
  168. }
  169. }
  170. catch (Exception ex)
  171. {
  172. if (activeChar.getDietMode())
  173. {
  174. activeChar.setDietMode(false);
  175. activeChar.sendMessage("Diet mode off");
  176. }
  177. else
  178. {
  179. activeChar.setDietMode(true);
  180. activeChar.sendMessage("Diet mode on");
  181. }
  182. }
  183. finally
  184. {
  185. activeChar.refreshOverloaded();
  186. }
  187. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  188. }
  189. else if (command.startsWith("admin_tradeoff"))
  190. {
  191. try
  192. {
  193. String mode = command.substring(15);
  194. if (mode.equalsIgnoreCase("on"))
  195. {
  196. activeChar.setTradeRefusal(true);
  197. activeChar.sendMessage("Trade refusal enabled");
  198. }
  199. else if (mode.equalsIgnoreCase("off"))
  200. {
  201. activeChar.setTradeRefusal(false);
  202. activeChar.sendMessage("Trade refusal disabled");
  203. }
  204. }
  205. catch (Exception ex)
  206. {
  207. if (activeChar.getTradeRefusal())
  208. {
  209. activeChar.setTradeRefusal(false);
  210. activeChar.sendMessage("Trade refusal disabled");
  211. }
  212. else
  213. {
  214. activeChar.setTradeRefusal(true);
  215. activeChar.sendMessage("Trade refusal enabled");
  216. }
  217. }
  218. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  219. }
  220. else if (command.startsWith("admin_reload"))
  221. {
  222. StringTokenizer st = new StringTokenizer(command);
  223. st.nextToken();
  224. String type = "";
  225. try
  226. {
  227. type = st.nextToken();
  228. if (type.equals("multisell"))
  229. {
  230. MultiSell.getInstance().reload();
  231. activeChar.sendMessage("All Multisells 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);
  249. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  250. if (spawn != null && spawn.getNpcid() == npcId)
  251. spawn.respawnNpc(spawn.getLastSpawn());
  252. activeChar.sendMessage("NPC " + npcId + " have been reloaded");
  253. }
  254. }
  255. else if (type.equals("npc"))
  256. {
  257. NpcTable.getInstance().reloadAllNpc();
  258. QuestManager.getInstance().reloadAllQuests();
  259. activeChar.sendMessage("All NPCs have been reloaded");
  260. }
  261. else if (type.startsWith("htm"))
  262. {
  263. HtmCache.getInstance().reload();
  264. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  265. }
  266. else if (type.startsWith("item"))
  267. {
  268. ItemTable.getInstance().reload();
  269. activeChar.sendMessage("Item Templates have been reloaded");
  270. }
  271. else if (type.startsWith("config"))
  272. {
  273. Config.load();
  274. activeChar.sendMessage("All Config Settings have been reloaded");
  275. }
  276. else if (type.startsWith("instancemanager"))
  277. {
  278. Manager.reloadAll();
  279. activeChar.sendMessage("All Instance Manager has been reloaded");
  280. }
  281. else if (type.startsWith("npcwalkers"))
  282. {
  283. NpcWalkerRoutesTable.getInstance().load();
  284. activeChar.sendMessage("NPC Walker Routes have been reloaded");
  285. }
  286. else if (type.startsWith("access"))
  287. {
  288. AccessLevels.getInstance().reloadAccessLevels();
  289. AdminCommandAccessRights.getInstance().reloadAdminCommandAccessRights();
  290. activeChar.sendMessage("Access Rights have been reloaded");
  291. }
  292. else if (type.startsWith("quests"))
  293. {
  294. QuestManager.getInstance().reloadAllQuests();
  295. activeChar.sendMessage("All Quests have been reloaded");
  296. }
  297. else if (type.startsWith("door"))
  298. {
  299. DoorTable.getInstance().reloadAll();
  300. activeChar.sendMessage("All Doors have been reloaded");
  301. }
  302. 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.");
  303. }
  304. catch (Exception e)
  305. {
  306. activeChar.sendMessage("An error occured while reloading " + type + " !");
  307. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|instancemanager|npcwalkers|access|quests>");
  308. _log.warning("An error occured while reloading " + type + ": " + e); //do not mask an exception here
  309. }
  310. }
  311. else if (command.startsWith("admin_setconfig"))
  312. {
  313. StringTokenizer st = new StringTokenizer(command);
  314. st.nextToken();
  315. try
  316. {
  317. String pName = st.nextToken();
  318. String pValue = st.nextToken();
  319. if (Config.setParameterValue(pName, pValue))
  320. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  321. else
  322. activeChar.sendMessage("Invalid parameter!");
  323. }
  324. catch (Exception e)
  325. {
  326. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  327. }
  328. finally
  329. {
  330. showConfigPage(activeChar);
  331. }
  332. }
  333. else if (command.startsWith("admin_set"))
  334. {
  335. StringTokenizer st = new StringTokenizer(command);
  336. String[] cmd = st.nextToken().split("_");
  337. try
  338. {
  339. String[] parameter = st.nextToken().split("=");
  340. String pName = parameter[0].trim();
  341. String pValue = parameter[1].trim();
  342. if (Config.setParameterValue(pName, pValue))
  343. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  344. else
  345. activeChar.sendMessage("Invalid parameter!");
  346. }
  347. catch (Exception e)
  348. {
  349. if (cmd.length == 2)
  350. activeChar.sendMessage("Usage: //set parameter=value");
  351. }
  352. finally
  353. {
  354. if (cmd.length == 3)
  355. {
  356. if (cmd[2].equalsIgnoreCase("mod"))
  357. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  358. }
  359. }
  360. }
  361. else if (command.startsWith("admin_gmon"))
  362. {
  363. // nothing
  364. }
  365. return true;
  366. }
  367. @Override
  368. public String[] getAdminCommandList()
  369. {
  370. return ADMIN_COMMANDS;
  371. }
  372. private void showMainPage(L2PcInstance activeChar, String command)
  373. {
  374. int mode = 0;
  375. String filename = null;
  376. try
  377. {
  378. mode = Integer.parseInt(command.substring(11));
  379. }
  380. catch (Exception e)
  381. {
  382. }
  383. switch (mode)
  384. {
  385. case 1:
  386. filename = "main";
  387. break;
  388. case 2:
  389. filename = "game";
  390. break;
  391. case 3:
  392. filename = "effects";
  393. break;
  394. case 4:
  395. filename = "server";
  396. break;
  397. case 5:
  398. filename = "mods";
  399. break;
  400. case 6:
  401. filename = "char";
  402. break;
  403. case 7:
  404. filename = "gm";
  405. break;
  406. case 8:
  407. filename = "old";
  408. break;
  409. default:
  410. if (Config.GM_ADMIN_MENU_STYLE.equals("modern"))
  411. filename = "main";
  412. else
  413. filename = "classic";
  414. break;
  415. }
  416. AdminHelpPage.showHelpPage(activeChar, filename + "_menu.htm");
  417. }
  418. public void showConfigPage(L2PcInstance activeChar)
  419. {
  420. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  421. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  422. 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>");
  423. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  424. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  425. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate EXP</font> = "
  426. + Config.RATE_XP
  427. + "</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>");
  428. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate SP</font> = "
  429. + Config.RATE_SP
  430. + "</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>");
  431. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate Drop Spoil</font> = "
  432. + Config.RATE_DROP_SPOIL
  433. + "</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>");
  434. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  435. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  436. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Weapon</font> = "
  437. + Config.ENCHANT_CHANCE_WEAPON
  438. + "</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>");
  439. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Armor</font> = "
  440. + Config.ENCHANT_CHANCE_ARMOR
  441. + "</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>");
  442. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Jewelry</font> = "
  443. + Config.ENCHANT_CHANCE_JEWELRY
  444. + "</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>");
  445. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Stone</font> = "
  446. + Config.ENCHANT_CHANCE_ELEMENT_STONE
  447. + "</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>");
  448. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Crystal</font> = "
  449. + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL
  450. + "</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>");
  451. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Jewel</font> = "
  452. + Config.ENCHANT_CHANCE_ELEMENT_JEWEL
  453. + "</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>");
  454. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Energy</font> = "
  455. + Config.ENCHANT_CHANCE_ELEMENT_ENERGY
  456. + "</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>");
  457. replyMSG.append("</table></body></html>");
  458. adminReply.setHtml(replyMSG.toString());
  459. activeChar.sendPacket(adminReply);
  460. }
  461. }