AdminAdmin.java 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362
  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 javolution.text.TextBuilder;
  23. import com.l2jserver.Config;
  24. import com.l2jserver.gameserver.data.xml.impl.AdminData;
  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. AdminData.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. AdminData.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. if (!Hero.getInstance().isUnclaimedHero(target.getObjectId()))
  143. {
  144. activeChar.sendMessage("This player cannot claim the hero status.");
  145. return false;
  146. }
  147. Hero.getInstance().claimHero(target);
  148. }
  149. else if (command.startsWith("admin_diet"))
  150. {
  151. try
  152. {
  153. StringTokenizer st = new StringTokenizer(command);
  154. st.nextToken();
  155. if (st.nextToken().equalsIgnoreCase("on"))
  156. {
  157. activeChar.setDietMode(true);
  158. activeChar.sendMessage("Diet mode on");
  159. }
  160. else if (st.nextToken().equalsIgnoreCase("off"))
  161. {
  162. activeChar.setDietMode(false);
  163. activeChar.sendMessage("Diet mode off");
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. if (activeChar.getDietMode())
  169. {
  170. activeChar.setDietMode(false);
  171. activeChar.sendMessage("Diet mode off");
  172. }
  173. else
  174. {
  175. activeChar.setDietMode(true);
  176. activeChar.sendMessage("Diet mode on");
  177. }
  178. }
  179. finally
  180. {
  181. activeChar.refreshOverloaded();
  182. }
  183. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  184. }
  185. else if (command.startsWith("admin_tradeoff"))
  186. {
  187. try
  188. {
  189. String mode = command.substring(15);
  190. if (mode.equalsIgnoreCase("on"))
  191. {
  192. activeChar.setTradeRefusal(true);
  193. activeChar.sendMessage("Trade refusal enabled");
  194. }
  195. else if (mode.equalsIgnoreCase("off"))
  196. {
  197. activeChar.setTradeRefusal(false);
  198. activeChar.sendMessage("Trade refusal disabled");
  199. }
  200. }
  201. catch (Exception ex)
  202. {
  203. if (activeChar.getTradeRefusal())
  204. {
  205. activeChar.setTradeRefusal(false);
  206. activeChar.sendMessage("Trade refusal disabled");
  207. }
  208. else
  209. {
  210. activeChar.setTradeRefusal(true);
  211. activeChar.sendMessage("Trade refusal enabled");
  212. }
  213. }
  214. AdminHtml.showAdminHtml(activeChar, "gm_menu.htm");
  215. }
  216. else if (command.startsWith("admin_setconfig"))
  217. {
  218. StringTokenizer st = new StringTokenizer(command);
  219. st.nextToken();
  220. try
  221. {
  222. String pName = st.nextToken();
  223. String pValue = st.nextToken();
  224. if (Config.setParameterValue(pName, pValue))
  225. {
  226. activeChar.sendMessage("Config parameter " + pName + " set to " + pValue);
  227. }
  228. else
  229. {
  230. activeChar.sendMessage("Invalid parameter!");
  231. }
  232. }
  233. catch (Exception e)
  234. {
  235. activeChar.sendMessage("Usage: //setconfig <parameter> <value>");
  236. }
  237. finally
  238. {
  239. showConfigPage(activeChar);
  240. }
  241. }
  242. else if (command.startsWith("admin_set"))
  243. {
  244. StringTokenizer st = new StringTokenizer(command);
  245. String[] cmd = st.nextToken().split("_");
  246. try
  247. {
  248. String[] parameter = st.nextToken().split("=");
  249. String pName = parameter[0].trim();
  250. String pValue = parameter[1].trim();
  251. if (Config.setParameterValue(pName, pValue))
  252. {
  253. activeChar.sendMessage("parameter " + pName + " succesfully set to " + pValue);
  254. }
  255. else
  256. {
  257. activeChar.sendMessage("Invalid parameter!");
  258. }
  259. }
  260. catch (Exception e)
  261. {
  262. if (cmd.length == 2)
  263. {
  264. activeChar.sendMessage("Usage: //set parameter=value");
  265. }
  266. }
  267. finally
  268. {
  269. if (cmd.length == 3)
  270. {
  271. if (cmd[2].equalsIgnoreCase("mod"))
  272. {
  273. AdminHtml.showAdminHtml(activeChar, "mods_menu.htm");
  274. }
  275. }
  276. }
  277. }
  278. else if (command.startsWith("admin_gmon"))
  279. {
  280. // nothing
  281. }
  282. return true;
  283. }
  284. @Override
  285. public String[] getAdminCommandList()
  286. {
  287. return ADMIN_COMMANDS;
  288. }
  289. private void showMainPage(L2PcInstance activeChar, String command)
  290. {
  291. int mode = 0;
  292. String filename = null;
  293. try
  294. {
  295. mode = Integer.parseInt(command.substring(11));
  296. }
  297. catch (Exception e)
  298. {
  299. }
  300. switch (mode)
  301. {
  302. case 1:
  303. filename = "main";
  304. break;
  305. case 2:
  306. filename = "game";
  307. break;
  308. case 3:
  309. filename = "effects";
  310. break;
  311. case 4:
  312. filename = "server";
  313. break;
  314. case 5:
  315. filename = "mods";
  316. break;
  317. case 6:
  318. filename = "char";
  319. break;
  320. case 7:
  321. filename = "gm";
  322. break;
  323. default:
  324. filename = "main";
  325. break;
  326. }
  327. AdminHtml.showAdminHtml(activeChar, filename + "_menu.htm");
  328. }
  329. public void showConfigPage(L2PcInstance activeChar)
  330. {
  331. final NpcHtmlMessage adminReply = new NpcHtmlMessage();
  332. TextBuilder replyMSG = new TextBuilder("<html><title>L2J :: Config</title><body>");
  333. 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>");
  334. replyMSG.append("<center><table width=260><tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  335. replyMSG.append("<tr><td><font color=\"00AA00\">Drop:</font></td><td></td><td></td></tr>");
  336. 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>");
  337. 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>");
  338. 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>");
  339. replyMSG.append("<tr><td width=140></td><td width=40></td><td width=40></td></tr>");
  340. replyMSG.append("<tr><td><font color=\"00AA00\">Enchant:</font></td><td></td><td></td></tr>");
  341. 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>");
  342. 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>");
  343. 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>");
  344. 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>");
  345. replyMSG.append("</table></body></html>");
  346. adminReply.setHtml(replyMSG.toString());
  347. activeChar.sendPacket(adminReply);
  348. }
  349. }