AdminAdmin.java 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  1. /*
  2. * Copyright (C) 2004-2014 L2J DataPack
  3. *
  4. * This file is part of L2J DataPack.
  5. *
  6. * L2J DataPack is free software: you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation, either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * L2J DataPack is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package handlers.admincommandhandlers;
  20. import java.util.StringTokenizer;
  21. import java.util.logging.Logger;
  22. import javolution.text.TextBuilder;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.datatables.AdminTable;
  25. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  26. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  27. import com.l2jserver.gameserver.model.entity.Hero;
  28. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  29. import com.l2jserver.gameserver.network.SystemMessageId;
  30. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  31. /**
  32. * This class handles following admin commands: - admin|admin1/admin2/admin3/admin4/admin5 = slots for the 5 starting admin menus - gmliston/gmlistoff = includes/excludes active character from /gmlist results - silence = toggles private messages acceptance mode - diet = toggles weight penalty mode -
  33. * tradeoff = toggles trade acceptance mode - reload = reloads specified component from multisell|skill|npc|htm|item - set/set_menu/set_mod = alters specified server setting - saveolymp = saves olympiad state manually - manualhero = cycles olympiad and calculate new heroes.
  34. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  35. */
  36. public class AdminAdmin implements IAdminCommandHandler
  37. {
  38. private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  39. private static final String[] ADMIN_COMMANDS =
  40. {
  41. "admin_admin",
  42. "admin_admin1",
  43. "admin_admin2",
  44. "admin_admin3",
  45. "admin_admin4",
  46. "admin_admin5",
  47. "admin_admin6",
  48. "admin_admin7",
  49. "admin_gmliston",
  50. "admin_gmlistoff",
  51. "admin_silence",
  52. "admin_diet",
  53. "admin_tradeoff",
  54. "admin_set",
  55. "admin_set_mod",
  56. "admin_saveolymp",
  57. "admin_sethero",
  58. "admin_givehero",
  59. "admin_endolympiad",
  60. "admin_setconfig",
  61. "admin_config_server",
  62. "admin_gmon"
  63. };
  64. @Override
  65. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  66. {
  67. if (command.startsWith("admin_admin"))
  68. {
  69. showMainPage(activeChar, command);
  70. }
  71. else if (command.equals("admin_config_server"))
  72. {
  73. showConfigPage(activeChar);
  74. }
  75. else if (command.startsWith("admin_gmliston"))
  76. {
  77. AdminTable.getInstance().showGm(activeChar);
  78. activeChar.sendMessage("Registered into gm list");
  79. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  80. }
  81. else if (command.startsWith("admin_gmlistoff"))
  82. {
  83. AdminTable.getInstance().hideGm(activeChar);
  84. activeChar.sendMessage("Removed from gm list");
  85. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  86. }
  87. else if (command.startsWith("admin_silence"))
  88. {
  89. if (activeChar.isSilenceMode()) // already in message refusal mode
  90. {
  91. activeChar.setSilenceMode(false);
  92. activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  93. }
  94. else
  95. {
  96. activeChar.setSilenceMode(true);
  97. activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE);
  98. }
  99. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  100. }
  101. else if (command.startsWith("admin_saveolymp"))
  102. {
  103. Olympiad.getInstance().saveOlympiadStatus();
  104. activeChar.sendMessage("olympiad system saved.");
  105. }
  106. else if (command.startsWith("admin_endolympiad"))
  107. {
  108. try
  109. {
  110. Olympiad.getInstance().manualSelectHeroes();
  111. }
  112. catch (Exception e)
  113. {
  114. _log.warning("An error occured while ending olympiad: " + e);
  115. }
  116. activeChar.sendMessage("Heroes formed.");
  117. }
  118. else if (command.startsWith("admin_sethero"))
  119. {
  120. if (activeChar.getTarget() == null)
  121. {
  122. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  123. return false;
  124. }
  125. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  126. target.setHero(!target.isHero());
  127. target.broadcastUserInfo();
  128. }
  129. else if (command.startsWith("admin_givehero"))
  130. {
  131. if (activeChar.getTarget() == null)
  132. {
  133. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  134. return false;
  135. }
  136. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  137. if (Hero.getInstance().isHero(target.getObjectId()))
  138. {
  139. activeChar.sendMessage("This player has already claimed the hero status.");
  140. return false;
  141. }
  142. Hero.getInstance().claimHero(target);
  143. }
  144. else if (command.startsWith("admin_diet"))
  145. {
  146. try
  147. {
  148. StringTokenizer st = new StringTokenizer(command);
  149. st.nextToken();
  150. if (st.nextToken().equalsIgnoreCase("on"))
  151. {
  152. activeChar.setDietMode(true);
  153. activeChar.sendMessage("Diet mode on");
  154. }
  155. else if (st.nextToken().equalsIgnoreCase("off"))
  156. {
  157. activeChar.setDietMode(false);
  158. activeChar.sendMessage("Diet mode off");
  159. }
  160. }
  161. catch (Exception ex)
  162. {
  163. if (activeChar.getDietMode())
  164. {
  165. activeChar.setDietMode(false);
  166. activeChar.sendMessage("Diet mode off");
  167. }
  168. else
  169. {
  170. activeChar.setDietMode(true);
  171. activeChar.sendMessage("Diet mode on");
  172. }
  173. }
  174. finally
  175. {
  176. activeChar.refreshOverloaded();
  177. }
  178. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  179. }
  180. else if (command.startsWith("admin_tradeoff"))
  181. {
  182. try
  183. {
  184. String mode = command.substring(15);
  185. if (mode.equalsIgnoreCase("on"))
  186. {
  187. activeChar.setTradeRefusal(true);
  188. activeChar.sendMessage("Trade refusal enabled");
  189. }
  190. else if (mode.equalsIgnoreCase("off"))
  191. {
  192. activeChar.setTradeRefusal(false);
  193. activeChar.sendMessage("Trade refusal disabled");
  194. }
  195. }
  196. catch (Exception ex)
  197. {
  198. if (activeChar.getTradeRefusal())
  199. {
  200. activeChar.setTradeRefusal(false);
  201. activeChar.sendMessage("Trade refusal disabled");
  202. }
  203. else
  204. {
  205. activeChar.setTradeRefusal(true);
  206. activeChar.sendMessage("Trade refusal enabled");
  207. }
  208. }
  209. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  210. }
  211. else if (command.startsWith("admin_setconfig"))
  212. {
  213. StringTokenizer st = new StringTokenizer(command);
  214. st.nextToken();
  215. try
  216. {
  217. String pName = st.nextToken();
  218. String pValue = st.nextToken();
  219. if (Config.setParameterValue(pName, pValue))
  220. {
  221. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  222. }
  223. else
  224. {
  225. activeChar.sendMessage("Invalid parameter!");
  226. }
  227. }
  228. catch (Exception e)
  229. {
  230. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  231. }
  232. finally
  233. {
  234. showConfigPage(activeChar);
  235. }
  236. }
  237. else if (command.startsWith("admin_set"))
  238. {
  239. StringTokenizer st = new StringTokenizer(command);
  240. String[] cmd = st.nextToken().split("_");
  241. try
  242. {
  243. String[] parameter = st.nextToken().split("=");
  244. String pName = parameter[0].trim();
  245. String pValue = parameter[1].trim();
  246. if (Config.setParameterValue(pName, pValue))
  247. {
  248. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  249. }
  250. else
  251. {
  252. activeChar.sendMessage("Invalid parameter!");
  253. }
  254. }
  255. catch (Exception e)
  256. {
  257. if (cmd.length == 2)
  258. {
  259. activeChar.sendMessage("Usage: //set parameter=value");
  260. }
  261. }
  262. finally
  263. {
  264. if (cmd.length == 3)
  265. {
  266. if (cmd[2].equalsIgnoreCase("mod"))
  267. {
  268. AdminHtml.showAdminHtml(activeChar, "mods_menu.htm");
  269. }
  270. }
  271. }
  272. }
  273. else if (command.startsWith("admin_gmon"))
  274. {
  275. // nothing
  276. }
  277. return true;
  278. }
  279. @Override
  280. public String[] getAdminCommandList()
  281. {
  282. return ADMIN_COMMANDS;
  283. }
  284. private void showMainPage(L2PcInstance activeChar, String command)
  285. {
  286. int mode = 0;
  287. String filename = null;
  288. try
  289. {
  290. mode = Integer.parseInt(command.substring(11));
  291. }
  292. catch (Exception e)
  293. {
  294. }
  295. switch (mode)
  296. {
  297. case 1:
  298. filename = "main";
  299. break;
  300. case 2:
  301. filename = "game";
  302. break;
  303. case 3:
  304. filename = "effects";
  305. break;
  306. case 4:
  307. filename = "server";
  308. break;
  309. case 5:
  310. filename = "mods";
  311. break;
  312. case 6:
  313. filename = "char";
  314. break;
  315. case 7:
  316. filename = "gm";
  317. break;
  318. default:
  319. filename = "main";
  320. break;
  321. }
  322. AdminHtml.showAdminHtml(activeChar, filename + "_menu.htm");
  323. }
  324. public void showConfigPage(L2PcInstance activeChar)
  325. {
  326. final NpcHtmlMessage adminReply = new NpcHtmlMessage();
  327. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  328. 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>");
  329. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  330. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  331. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate EXP</font> = " + Config.RATE_XP + "</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>");
  332. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate SP</font> = " + Config.RATE_SP + "</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>");
  333. replyMSG.append("<tr><td><font color=\"LEVEL\">Rate Drop Spoil</font> = " + Config.RATE_CORPSE_DROP_CHANCE_MULTIPLIER + "</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>");
  334. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  335. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  336. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Stone</font> = " + Config.ENCHANT_CHANCE_ELEMENT_STONE + "</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>");
  337. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Crystal</font> = " + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL + "</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>");
  338. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Jewel</font> = " + Config.ENCHANT_CHANCE_ELEMENT_JEWEL + "</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>");
  339. replyMSG.append("<tr><td><font color=\"LEVEL\">Enchant Element Energy</font> = " + Config.ENCHANT_CHANCE_ELEMENT_ENERGY + "</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>");
  340. replyMSG.append("</table></body></html>");
  341. adminReply.setHtml(replyMSG.toString());
  342. activeChar.sendPacket(adminReply);
  343. }
  344. }