AdminAdmin.java 16 KB

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