AdminAdmin.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462
  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.Level;
  18. import java.util.logging.Logger;
  19. import javolution.text.TextBuilder;
  20. import com.l2jserver.Config;
  21. import com.l2jserver.gameserver.cache.HtmCache;
  22. import com.l2jserver.gameserver.datatables.AdminTable;
  23. import com.l2jserver.gameserver.datatables.DoorTable;
  24. import com.l2jserver.gameserver.datatables.ItemTable;
  25. import com.l2jserver.gameserver.datatables.MultiSell;
  26. import com.l2jserver.gameserver.datatables.NpcTable;
  27. import com.l2jserver.gameserver.datatables.NpcWalkerRoutesData;
  28. import com.l2jserver.gameserver.datatables.SkillTable;
  29. import com.l2jserver.gameserver.datatables.SpawnTable;
  30. import com.l2jserver.gameserver.datatables.TeleportLocationTable;
  31. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  32. import com.l2jserver.gameserver.instancemanager.QuestManager;
  33. import com.l2jserver.gameserver.model.L2Spawn;
  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. /**
  39. * This class handles following admin commands:
  40. * - admin|admin1/admin2/admin3/admin4/admin5 = slots for the 5 starting admin menus
  41. * - gmliston/gmlistoff = includes/excludes active character from /gmlist results
  42. * - silence = toggles private messages acceptance mode
  43. * - diet = toggles weight penalty mode
  44. * - tradeoff = toggles trade acceptance mode
  45. * - reload = reloads specified component from multisell|skill|npc|htm|item
  46. * - set/set_menu/set_mod = alters specified server setting
  47. * - saveolymp = saves olympiad state manually
  48. * - manualhero = cycles olympiad and calculate new heroes.
  49. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  50. */
  51. public class AdminAdmin implements IAdminCommandHandler
  52. {
  53. private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  54. private static final String[] ADMIN_COMMANDS =
  55. {
  56. "admin_admin",
  57. "admin_admin1",
  58. "admin_admin2",
  59. "admin_admin3",
  60. "admin_admin4",
  61. "admin_admin5",
  62. "admin_admin6",
  63. "admin_admin7",
  64. "admin_admin8",
  65. "admin_gmliston",
  66. "admin_gmlistoff",
  67. "admin_silence",
  68. "admin_diet",
  69. "admin_tradeoff",
  70. "admin_reload",
  71. "admin_set",
  72. "admin_set_mod",
  73. "admin_saveolymp",
  74. "admin_manualhero",
  75. "admin_sethero",
  76. "admin_endolympiad",
  77. "admin_setconfig",
  78. "admin_config_server",
  79. "admin_gmon"
  80. };
  81. @Override
  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. AdminTable.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. AdminTable.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(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  110. }
  111. else
  112. {
  113. activeChar.setSilenceMode(true);
  114. activeChar.sendPacket(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().isPlayer())
  139. {
  140. target = activeChar.getTarget().getActingPlayer();
  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. if (!st.hasMoreTokens())
  222. {
  223. activeChar.sendMessage("You need to specify a type to reload!");
  224. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  225. return false;
  226. }
  227. final String type = st.nextToken();
  228. try
  229. {
  230. if (type.equals("multisell"))
  231. {
  232. MultiSell.getInstance().reload();
  233. activeChar.sendMessage("All Multisells have been reloaded");
  234. }
  235. else if (type.startsWith("teleport"))
  236. {
  237. TeleportLocationTable.getInstance().reloadAll();
  238. activeChar.sendMessage("Teleport Locations have been reloaded");
  239. }
  240. else if (type.startsWith("skill"))
  241. {
  242. SkillTable.getInstance().reload();
  243. activeChar.sendMessage("All Skills have been reloaded");
  244. }
  245. else if (type.startsWith("npcId"))
  246. {
  247. Integer npcId = Integer.parseInt(st.nextToken());
  248. if (npcId != null)
  249. {
  250. NpcTable.getInstance().reloadNpc(npcId);
  251. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  252. if (spawn != null && spawn.getNpcid() == npcId)
  253. spawn.respawnNpc(spawn.getLastSpawn());
  254. activeChar.sendMessage("NPC " + npcId + " have been reloaded");
  255. }
  256. }
  257. else if (type.equals("npc"))
  258. {
  259. NpcTable.getInstance().reloadAllNpc();
  260. QuestManager.getInstance().reloadAllQuests();
  261. activeChar.sendMessage("All NPCs have been reloaded");
  262. }
  263. else if (type.startsWith("htm"))
  264. {
  265. HtmCache.getInstance().reload();
  266. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  267. }
  268. else if (type.startsWith("item"))
  269. {
  270. ItemTable.getInstance().reload();
  271. activeChar.sendMessage("Item Templates have been reloaded");
  272. }
  273. else if (type.startsWith("config"))
  274. {
  275. Config.load();
  276. activeChar.sendMessage("All Config Settings have been reloaded");
  277. }
  278. else if (type.startsWith("npcwalkers"))
  279. {
  280. NpcWalkerRoutesData.getInstance().load();
  281. activeChar.sendMessage("NPC Walker Routes have been reloaded");
  282. }
  283. else if (type.startsWith("access"))
  284. {
  285. AdminTable.getInstance().load();
  286. activeChar.sendMessage("Access Rights have been reloaded");
  287. }
  288. else if (type.startsWith("quests"))
  289. {
  290. QuestManager.getInstance().reloadAllQuests();
  291. activeChar.sendMessage("All Quests have been reloaded.");
  292. }
  293. else if (type.startsWith("door"))
  294. {
  295. DoorTable.getInstance().load();
  296. activeChar.sendMessage("All Doors have been reloaded");
  297. }
  298. 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.");
  299. }
  300. catch (Exception e)
  301. {
  302. activeChar.sendMessage("An error occured while reloading " + type + " !");
  303. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  304. _log.log(Level.WARNING, "An error occured while reloading " + type + ": " + e, e);
  305. }
  306. }
  307. else if (command.startsWith("admin_setconfig"))
  308. {
  309. StringTokenizer st = new StringTokenizer(command);
  310. st.nextToken();
  311. try
  312. {
  313. String pName = st.nextToken();
  314. String pValue = st.nextToken();
  315. if (Config.setParameterValue(pName, pValue))
  316. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  317. else
  318. activeChar.sendMessage("Invalid parameter!");
  319. }
  320. catch (Exception e)
  321. {
  322. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  323. }
  324. finally
  325. {
  326. showConfigPage(activeChar);
  327. }
  328. }
  329. else if (command.startsWith("admin_set"))
  330. {
  331. StringTokenizer st = new StringTokenizer(command);
  332. String[] cmd = st.nextToken().split("_");
  333. try
  334. {
  335. String[] parameter = st.nextToken().split("=");
  336. String pName = parameter[0].trim();
  337. String pValue = parameter[1].trim();
  338. if (Config.setParameterValue(pName, pValue))
  339. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  340. else
  341. activeChar.sendMessage("Invalid parameter!");
  342. }
  343. catch (Exception e)
  344. {
  345. if (cmd.length == 2)
  346. activeChar.sendMessage("Usage: //set parameter=value");
  347. }
  348. finally
  349. {
  350. if (cmd.length == 3)
  351. {
  352. if (cmd[2].equalsIgnoreCase("mod"))
  353. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  354. }
  355. }
  356. }
  357. else if (command.startsWith("admin_gmon"))
  358. {
  359. // nothing
  360. }
  361. return true;
  362. }
  363. @Override
  364. public String[] getAdminCommandList()
  365. {
  366. return ADMIN_COMMANDS;
  367. }
  368. private void showMainPage(L2PcInstance activeChar, String command)
  369. {
  370. int mode = 0;
  371. String filename = null;
  372. try
  373. {
  374. mode = Integer.parseInt(command.substring(11));
  375. }
  376. catch (Exception e)
  377. {
  378. }
  379. switch (mode)
  380. {
  381. case 1:
  382. filename = "main";
  383. break;
  384. case 2:
  385. filename = "game";
  386. break;
  387. case 3:
  388. filename = "effects";
  389. break;
  390. case 4:
  391. filename = "server";
  392. break;
  393. case 5:
  394. filename = "mods";
  395. break;
  396. case 6:
  397. filename = "char";
  398. break;
  399. case 7:
  400. filename = "gm";
  401. break;
  402. case 8:
  403. filename = "old";
  404. break;
  405. default:
  406. if (Config.GM_ADMIN_MENU_STYLE.equals("modern"))
  407. filename = "main";
  408. else
  409. filename = "classic";
  410. break;
  411. }
  412. AdminHelpPage.showHelpPage(activeChar, filename + "_menu.htm");
  413. }
  414. public void showConfigPage(L2PcInstance activeChar)
  415. {
  416. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  417. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  418. 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>");
  419. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  420. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  421. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate EXP</font> = "
  422. + Config.RATE_XP
  423. + "</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>");
  424. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate SP</font> = "
  425. + Config.RATE_SP
  426. + "</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>");
  427. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate Drop Spoil</font> = "
  428. + Config.RATE_DROP_SPOIL
  429. + "</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>");
  430. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  431. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  432. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Stone</font> = "
  433. + Config.ENCHANT_CHANCE_ELEMENT_STONE
  434. + "</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>");
  435. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Crystal</font> = "
  436. + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL
  437. + "</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>");
  438. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Jewel</font> = "
  439. + Config.ENCHANT_CHANCE_ELEMENT_JEWEL
  440. + "</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>");
  441. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Energy</font> = "
  442. + Config.ENCHANT_CHANCE_ELEMENT_ENERGY
  443. + "</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>");
  444. replyMSG.append("</table></body></html>");
  445. adminReply.setHtml(replyMSG.toString());
  446. activeChar.sendPacket(adminReply);
  447. }
  448. }