AdminAdmin.java 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  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. if (activeChar.getTarget() == null)
  138. {
  139. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  140. return false;
  141. }
  142. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  143. target.setHero(!target.isHero());
  144. target.broadcastUserInfo();
  145. }
  146. else if (command.startsWith("admin_diet"))
  147. {
  148. try
  149. {
  150. StringTokenizer st = new StringTokenizer(command);
  151. st.nextToken();
  152. if (st.nextToken().equalsIgnoreCase("on"))
  153. {
  154. activeChar.setDietMode(true);
  155. activeChar.sendMessage("Diet mode on");
  156. }
  157. else if (st.nextToken().equalsIgnoreCase("off"))
  158. {
  159. activeChar.setDietMode(false);
  160. activeChar.sendMessage("Diet mode off");
  161. }
  162. }
  163. catch (Exception ex)
  164. {
  165. if (activeChar.getDietMode())
  166. {
  167. activeChar.setDietMode(false);
  168. activeChar.sendMessage("Diet mode off");
  169. }
  170. else
  171. {
  172. activeChar.setDietMode(true);
  173. activeChar.sendMessage("Diet mode on");
  174. }
  175. }
  176. finally
  177. {
  178. activeChar.refreshOverloaded();
  179. }
  180. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  181. }
  182. else if (command.startsWith("admin_tradeoff"))
  183. {
  184. try
  185. {
  186. String mode = command.substring(15);
  187. if (mode.equalsIgnoreCase("on"))
  188. {
  189. activeChar.setTradeRefusal(true);
  190. activeChar.sendMessage("Trade refusal enabled");
  191. }
  192. else if (mode.equalsIgnoreCase("off"))
  193. {
  194. activeChar.setTradeRefusal(false);
  195. activeChar.sendMessage("Trade refusal disabled");
  196. }
  197. }
  198. catch (Exception ex)
  199. {
  200. if (activeChar.getTradeRefusal())
  201. {
  202. activeChar.setTradeRefusal(false);
  203. activeChar.sendMessage("Trade refusal disabled");
  204. }
  205. else
  206. {
  207. activeChar.setTradeRefusal(true);
  208. activeChar.sendMessage("Trade refusal enabled");
  209. }
  210. }
  211. AdminHelpPage.showHelpPage(activeChar,"gm_menu.htm");
  212. }
  213. else if (command.startsWith("admin_reload"))
  214. {
  215. StringTokenizer st = new StringTokenizer(command);
  216. st.nextToken();
  217. if (!st.hasMoreTokens())
  218. {
  219. activeChar.sendMessage("You need to specify a type to reload!");
  220. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  221. return false;
  222. }
  223. final String type = st.nextToken();
  224. try
  225. {
  226. if (type.equals("multisell"))
  227. {
  228. MultiSell.getInstance().reload();
  229. activeChar.sendMessage("All Multisells have been reloaded");
  230. }
  231. else if (type.startsWith("teleport"))
  232. {
  233. TeleportLocationTable.getInstance().reloadAll();
  234. activeChar.sendMessage("Teleport Locations have been reloaded");
  235. }
  236. else if (type.startsWith("skill"))
  237. {
  238. SkillTable.getInstance().reload();
  239. activeChar.sendMessage("All Skills have been reloaded");
  240. }
  241. else if (type.startsWith("npcId"))
  242. {
  243. Integer npcId = Integer.parseInt(st.nextToken());
  244. if (npcId != null)
  245. {
  246. NpcTable.getInstance().reloadNpc(npcId);
  247. for (L2Spawn spawn : SpawnTable.getInstance().getSpawnTable())
  248. if (spawn != null && spawn.getNpcid() == npcId)
  249. spawn.respawnNpc(spawn.getLastSpawn());
  250. activeChar.sendMessage("NPC " + npcId + " have been reloaded");
  251. }
  252. }
  253. else if (type.equals("npc"))
  254. {
  255. NpcTable.getInstance().reloadAllNpc();
  256. QuestManager.getInstance().reloadAllQuests();
  257. activeChar.sendMessage("All NPCs have been reloaded");
  258. }
  259. else if (type.startsWith("htm"))
  260. {
  261. HtmCache.getInstance().reload();
  262. activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded");
  263. }
  264. else if (type.startsWith("item"))
  265. {
  266. ItemTable.getInstance().reload();
  267. activeChar.sendMessage("Item Templates have been reloaded");
  268. }
  269. else if (type.startsWith("config"))
  270. {
  271. Config.load();
  272. activeChar.sendMessage("All Config Settings have been reloaded");
  273. }
  274. else if (type.startsWith("npcwalkers"))
  275. {
  276. NpcWalkerRoutesData.getInstance().load();
  277. activeChar.sendMessage("NPC Walker Routes have been reloaded");
  278. }
  279. else if (type.startsWith("access"))
  280. {
  281. AdminTable.getInstance().load();
  282. activeChar.sendMessage("Access Rights have been reloaded");
  283. }
  284. else if (type.startsWith("quests"))
  285. {
  286. QuestManager.getInstance().reloadAllQuests();
  287. activeChar.sendMessage("All Quests have been reloaded.");
  288. }
  289. else if (type.startsWith("door"))
  290. {
  291. DoorTable.getInstance().load();
  292. activeChar.sendMessage("All Doors have been reloaded");
  293. }
  294. 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.");
  295. }
  296. catch (Exception e)
  297. {
  298. activeChar.sendMessage("An error occured while reloading " + type + " !");
  299. activeChar.sendMessage("Usage: //reload <multisell|teleport|skill|npc|htm|item|config|npcwalkers|access|quests>");
  300. _log.log(Level.WARNING, "An error occured while reloading " + type + ": " + e, e);
  301. }
  302. }
  303. else if (command.startsWith("admin_setconfig"))
  304. {
  305. StringTokenizer st = new StringTokenizer(command);
  306. st.nextToken();
  307. try
  308. {
  309. String pName = st.nextToken();
  310. String pValue = st.nextToken();
  311. if (Config.setParameterValue(pName, pValue))
  312. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  313. else
  314. activeChar.sendMessage("Invalid parameter!");
  315. }
  316. catch (Exception e)
  317. {
  318. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  319. }
  320. finally
  321. {
  322. showConfigPage(activeChar);
  323. }
  324. }
  325. else if (command.startsWith("admin_set"))
  326. {
  327. StringTokenizer st = new StringTokenizer(command);
  328. String[] cmd = st.nextToken().split("_");
  329. try
  330. {
  331. String[] parameter = st.nextToken().split("=");
  332. String pName = parameter[0].trim();
  333. String pValue = parameter[1].trim();
  334. if (Config.setParameterValue(pName, pValue))
  335. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  336. else
  337. activeChar.sendMessage("Invalid parameter!");
  338. }
  339. catch (Exception e)
  340. {
  341. if (cmd.length == 2)
  342. activeChar.sendMessage("Usage: //set parameter=value");
  343. }
  344. finally
  345. {
  346. if (cmd.length == 3)
  347. {
  348. if (cmd[2].equalsIgnoreCase("mod"))
  349. AdminHelpPage.showHelpPage(activeChar, "mods_menu.htm");
  350. }
  351. }
  352. }
  353. else if (command.startsWith("admin_gmon"))
  354. {
  355. // nothing
  356. }
  357. return true;
  358. }
  359. @Override
  360. public String[] getAdminCommandList()
  361. {
  362. return ADMIN_COMMANDS;
  363. }
  364. private void showMainPage(L2PcInstance activeChar, String command)
  365. {
  366. int mode = 0;
  367. String filename = null;
  368. try
  369. {
  370. mode = Integer.parseInt(command.substring(11));
  371. }
  372. catch (Exception e)
  373. {
  374. }
  375. switch (mode)
  376. {
  377. case 1:
  378. filename = "main";
  379. break;
  380. case 2:
  381. filename = "game";
  382. break;
  383. case 3:
  384. filename = "effects";
  385. break;
  386. case 4:
  387. filename = "server";
  388. break;
  389. case 5:
  390. filename = "mods";
  391. break;
  392. case 6:
  393. filename = "char";
  394. break;
  395. case 7:
  396. filename = "gm";
  397. break;
  398. case 8:
  399. filename = "old";
  400. break;
  401. default:
  402. if (Config.GM_ADMIN_MENU_STYLE.equals("modern"))
  403. filename = "main";
  404. else
  405. filename = "classic";
  406. break;
  407. }
  408. AdminHelpPage.showHelpPage(activeChar, filename + "_menu.htm");
  409. }
  410. public void showConfigPage(L2PcInstance activeChar)
  411. {
  412. NpcHtmlMessage adminReply = new NpcHtmlMessage(5);
  413. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  414. 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>");
  415. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  416. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  417. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate EXP</font> = "
  418. + Config.RATE_XP
  419. + "</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>");
  420. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate SP</font> = "
  421. + Config.RATE_SP
  422. + "</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>");
  423. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate Drop Spoil</font> = "
  424. + Config.RATE_DROP_SPOIL
  425. + "</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>");
  426. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  427. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  428. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Stone</font> = "
  429. + Config.ENCHANT_CHANCE_ELEMENT_STONE
  430. + "</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>");
  431. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Crystal</font> = "
  432. + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL
  433. + "</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>");
  434. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Jewel</font> = "
  435. + Config.ENCHANT_CHANCE_ELEMENT_JEWEL
  436. + "</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>");
  437. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Energy</font> = "
  438. + Config.ENCHANT_CHANCE_ELEMENT_ENERGY
  439. + "</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>");
  440. replyMSG.append("</table></body></html>");
  441. adminReply.setHtml(replyMSG.toString());
  442. activeChar.sendPacket(adminReply);
  443. }
  444. }