AdminAdmin.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360
  1. /*
  2. * Copyright (C) 2004-2015 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 com.l2jserver.Config;
  23. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  24. import com.l2jserver.gameserver.handler.IAdminCommandHandler;
  25. import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
  26. import com.l2jserver.gameserver.model.entity.Hero;
  27. import com.l2jserver.gameserver.model.olympiad.Olympiad;
  28. import com.l2jserver.gameserver.network.SystemMessageId;
  29. import com.l2jserver.gameserver.network.serverpackets.NpcHtmlMessage;
  30. /**
  31. * 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 -
  32. * 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.
  33. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $
  34. */
  35. public class AdminAdmin implements IAdminCommandHandler
  36. {
  37. private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName());
  38. private static final String[] ADMIN_COMMANDS =
  39. {
  40. "admin_admin",
  41. "admin_admin1",
  42. "admin_admin2",
  43. "admin_admin3",
  44. "admin_admin4",
  45. "admin_admin5",
  46. "admin_admin6",
  47. "admin_admin7",
  48. "admin_gmliston",
  49. "admin_gmlistoff",
  50. "admin_silence",
  51. "admin_diet",
  52. "admin_tradeoff",
  53. "admin_set",
  54. "admin_set_mod",
  55. "admin_saveolymp",
  56. "admin_sethero",
  57. "admin_givehero",
  58. "admin_endolympiad",
  59. "admin_setconfig",
  60. "admin_config_server",
  61. "admin_gmon"
  62. };
  63. @Override
  64. public boolean useAdminCommand(String command, L2PcInstance activeChar)
  65. {
  66. if (command.startsWith("admin_admin"))
  67. {
  68. showMainPage(activeChar, command);
  69. }
  70. else if (command.equals("admin_config_server"))
  71. {
  72. showConfigPage(activeChar);
  73. }
  74. else if (command.startsWith("admin_gmliston"))
  75. {
  76. AdminData.getInstance().showGm(activeChar);
  77. activeChar.sendMessage("Registered into gm list");
  78. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  79. }
  80. else if (command.startsWith("admin_gmlistoff"))
  81. {
  82. AdminData.getInstance().hideGm(activeChar);
  83. activeChar.sendMessage("Removed from gm list");
  84. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  85. }
  86. else if (command.startsWith("admin_silence"))
  87. {
  88. if (activeChar.isSilenceMode()) // already in message refusal mode
  89. {
  90. activeChar.setSilenceMode(false);
  91. activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE);
  92. }
  93. else
  94. {
  95. activeChar.setSilenceMode(true);
  96. activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE);
  97. }
  98. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  99. }
  100. else if (command.startsWith("admin_saveolymp"))
  101. {
  102. Olympiad.getInstance().saveOlympiadStatus();
  103. activeChar.sendMessage("olympiad system saved.");
  104. }
  105. else if (command.startsWith("admin_endolympiad"))
  106. {
  107. try
  108. {
  109. Olympiad.getInstance().manualSelectHeroes();
  110. }
  111. catch (Exception e)
  112. {
  113. _log.warning("An error occured while ending olympiad: " + e);
  114. }
  115. activeChar.sendMessage("Heroes formed.");
  116. }
  117. else if (command.startsWith("admin_sethero"))
  118. {
  119. if (activeChar.getTarget() == null)
  120. {
  121. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  122. return false;
  123. }
  124. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  125. target.setHero(!target.isHero());
  126. target.broadcastUserInfo();
  127. }
  128. else if (command.startsWith("admin_givehero"))
  129. {
  130. if (activeChar.getTarget() == null)
  131. {
  132. activeChar.sendPacket(SystemMessageId.INCORRECT_TARGET);
  133. return false;
  134. }
  135. final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar;
  136. if (Hero.getInstance().isHero(target.getObjectId()))
  137. {
  138. activeChar.sendMessage("This player has already claimed the hero status.");
  139. return false;
  140. }
  141. if (!Hero.getInstance().isUnclaimedHero(target.getObjectId()))
  142. {
  143. activeChar.sendMessage("This player cannot claim the hero status.");
  144. return false;
  145. }
  146. Hero.getInstance().claimHero(target);
  147. }
  148. else if (command.startsWith("admin_diet"))
  149. {
  150. try
  151. {
  152. StringTokenizer st = new StringTokenizer(command);
  153. st.nextToken();
  154. if (st.nextToken().equalsIgnoreCase("on"))
  155. {
  156. activeChar.setDietMode(true);
  157. activeChar.sendMessage("Diet mode on");
  158. }
  159. else if (st.nextToken().equalsIgnoreCase("off"))
  160. {
  161. activeChar.setDietMode(false);
  162. activeChar.sendMessage("Diet mode off");
  163. }
  164. }
  165. catch (Exception ex)
  166. {
  167. if (activeChar.getDietMode())
  168. {
  169. activeChar.setDietMode(false);
  170. activeChar.sendMessage("Diet mode off");
  171. }
  172. else
  173. {
  174. activeChar.setDietMode(true);
  175. activeChar.sendMessage("Diet mode on");
  176. }
  177. }
  178. finally
  179. {
  180. activeChar.refreshOverloaded();
  181. }
  182. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  183. }
  184. else if (command.startsWith("admin_tradeoff"))
  185. {
  186. try
  187. {
  188. String mode = command.substring(15);
  189. if (mode.equalsIgnoreCase("on"))
  190. {
  191. activeChar.setTradeRefusal(true);
  192. activeChar.sendMessage("Trade refusal enabled");
  193. }
  194. else if (mode.equalsIgnoreCase("off"))
  195. {
  196. activeChar.setTradeRefusal(false);
  197. activeChar.sendMessage("Trade refusal disabled");
  198. }
  199. }
  200. catch (Exception ex)
  201. {
  202. if (activeChar.getTradeRefusal())
  203. {
  204. activeChar.setTradeRefusal(false);
  205. activeChar.sendMessage("Trade refusal disabled");
  206. }
  207. else
  208. {
  209. activeChar.setTradeRefusal(true);
  210. activeChar.sendMessage("Trade refusal enabled");
  211. }
  212. }
  213. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  214. }
  215. else if (command.startsWith("admin_setconfig"))
  216. {
  217. StringTokenizer st = new StringTokenizer(command);
  218. st.nextToken();
  219. try
  220. {
  221. String pName = st.nextToken();
  222. String pValue = st.nextToken();
  223. if (Config.setParameterValue(pName, pValue))
  224. {
  225. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  226. }
  227. else
  228. {
  229. activeChar.sendMessage("Invalid parameter!");
  230. }
  231. }
  232. catch (Exception e)
  233. {
  234. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  235. }
  236. finally
  237. {
  238. showConfigPage(activeChar);
  239. }
  240. }
  241. else if (command.startsWith("admin_set"))
  242. {
  243. StringTokenizer st = new StringTokenizer(command);
  244. String[] cmd = st.nextToken().split("_");
  245. try
  246. {
  247. String[] parameter = st.nextToken().split("=");
  248. String pName = parameter[0].trim();
  249. String pValue = parameter[1].trim();
  250. if (Config.setParameterValue(pName, pValue))
  251. {
  252. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  253. }
  254. else
  255. {
  256. activeChar.sendMessage("Invalid parameter!");
  257. }
  258. }
  259. catch (Exception e)
  260. {
  261. if (cmd.length == 2)
  262. {
  263. activeChar.sendMessage("Usage: //set parameter=value");
  264. }
  265. }
  266. finally
  267. {
  268. if (cmd.length == 3)
  269. {
  270. if (cmd[2].equalsIgnoreCase("mod"))
  271. {
  272. AdminHtml.showAdminHtml(activeChar, "mods_menu.htm");
  273. }
  274. }
  275. }
  276. }
  277. else if (command.startsWith("admin_gmon"))
  278. {
  279. // nothing
  280. }
  281. return true;
  282. }
  283. @Override
  284. public String[] getAdminCommandList()
  285. {
  286. return ADMIN_COMMANDS;
  287. }
  288. private void showMainPage(L2PcInstance activeChar, String command)
  289. {
  290. int mode = 0;
  291. String filename = null;
  292. try
  293. {
  294. mode = Integer.parseInt(command.substring(11));
  295. }
  296. catch (Exception e)
  297. {
  298. }
  299. switch (mode)
  300. {
  301. case 1:
  302. filename = "main";
  303. break;
  304. case 2:
  305. filename = "game";
  306. break;
  307. case 3:
  308. filename = "effects";
  309. break;
  310. case 4:
  311. filename = "server";
  312. break;
  313. case 5:
  314. filename = "mods";
  315. break;
  316. case 6:
  317. filename = "char";
  318. break;
  319. case 7:
  320. filename = "gm";
  321. break;
  322. default:
  323. filename = "main";
  324. break;
  325. }
  326. AdminHtml.showAdminHtml(activeChar, filename + "_menu.htm");
  327. }
  328. public void showConfigPage(L2PcInstance activeChar)
  329. {
  330. final NpcHtmlMessage adminReply = new NpcHtmlMessage();
  331. StringBuilder replyMSG = new StringBuilder("<html><title>L2J :: Config</title><body>");
  332. 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>");
  333. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  334. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  335. 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>");
  336. 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>");
  337. 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>");
  338. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  339. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  340. 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>");
  341. 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>");
  342. 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>");
  343. 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>");
  344. replyMSG.append("</table></body></html>");
  345. adminReply.setHtml(replyMSG.toString());
  346. activeChar.sendPacket(adminReply);
  347. }
  348. }