/* * This file is part of the L2J Mobius project. * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ package handlers.admincommandhandlers; import java.util.StringTokenizer; import java.util.logging.Logger; import com.l2jmobius.Config; import com.l2jmobius.gameserver.data.xml.impl.AdminData; import com.l2jmobius.gameserver.enums.ChatType; import com.l2jmobius.gameserver.handler.IAdminCommandHandler; import com.l2jmobius.gameserver.model.L2Object; import com.l2jmobius.gameserver.model.L2World; import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance; import com.l2jmobius.gameserver.model.entity.Hero; import com.l2jmobius.gameserver.model.olympiad.Olympiad; import com.l2jmobius.gameserver.network.SystemMessageId; import com.l2jmobius.gameserver.network.serverpackets.CreatureSay; import com.l2jmobius.gameserver.network.serverpackets.ExWorldChatCnt; import com.l2jmobius.gameserver.network.serverpackets.NpcHtmlMessage; import com.l2jmobius.gameserver.util.Util; /** * 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 - * 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. * @version $Revision: 1.3.2.1.2.4 $ $Date: 2007/07/28 10:06:06 $ */ public class AdminAdmin implements IAdminCommandHandler { private static final Logger _log = Logger.getLogger(AdminAdmin.class.getName()); private static final String[] ADMIN_COMMANDS = { "admin_admin", "admin_admin1", "admin_admin2", "admin_admin3", "admin_admin4", "admin_admin5", "admin_admin6", "admin_admin7", "admin_gmliston", "admin_gmlistoff", "admin_silence", "admin_diet", "admin_tradeoff", "admin_set", "admin_set_mod", "admin_saveolymp", "admin_sethero", "admin_settruehero", "admin_givehero", "admin_endolympiad", "admin_setconfig", "admin_config_server", "admin_gmon", "admin_worldchat", }; @Override public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (command.startsWith("admin_admin")) { showMainPage(activeChar, command); } else if (command.equals("admin_config_server")) { showConfigPage(activeChar); } else if (command.startsWith("admin_gmliston")) { AdminData.getInstance().showGm(activeChar); activeChar.sendMessage("Registered into gm list"); AdminHtml.showAdminHtml(activeChar, "gm_menu.htm"); } else if (command.startsWith("admin_gmlistoff")) { AdminData.getInstance().hideGm(activeChar); activeChar.sendMessage("Removed from gm list"); AdminHtml.showAdminHtml(activeChar, "gm_menu.htm"); } else if (command.startsWith("admin_silence")) { if (activeChar.isSilenceMode()) // already in message refusal mode { activeChar.setSilenceMode(false); activeChar.sendPacket(SystemMessageId.MESSAGE_ACCEPTANCE_MODE); } else { activeChar.setSilenceMode(true); activeChar.sendPacket(SystemMessageId.MESSAGE_REFUSAL_MODE); } AdminHtml.showAdminHtml(activeChar, "gm_menu.htm"); } else if (command.startsWith("admin_saveolymp")) { Olympiad.getInstance().saveOlympiadStatus(); activeChar.sendMessage("olympiad system saved."); } else if (command.startsWith("admin_endolympiad")) { try { Olympiad.getInstance().manualSelectHeroes(); } catch (Exception e) { _log.warning("An error occured while ending olympiad: " + e); } activeChar.sendMessage("Heroes formed."); } else if (command.startsWith("admin_sethero")) { if (activeChar.getTarget() == null) { activeChar.sendPacket(SystemMessageId.INVALID_TARGET); return false; } final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar; target.setHero(!target.isHero()); target.broadcastUserInfo(); } else if (command.startsWith("admin_settruehero")) { if (activeChar.getTarget() == null) { activeChar.sendPacket(SystemMessageId.INVALID_TARGET); return false; } final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar; target.setTrueHero(!target.isTrueHero()); target.broadcastUserInfo(); } else if (command.startsWith("admin_givehero")) { if (activeChar.getTarget() == null) { activeChar.sendPacket(SystemMessageId.INVALID_TARGET); return false; } final L2PcInstance target = activeChar.getTarget().isPlayer() ? activeChar.getTarget().getActingPlayer() : activeChar; if (Hero.getInstance().isHero(target.getObjectId())) { activeChar.sendMessage("This player has already claimed the hero status."); return false; } if (!Hero.getInstance().isUnclaimedHero(target.getObjectId())) { activeChar.sendMessage("This player cannot claim the hero status."); return false; } Hero.getInstance().claimHero(target); } else if (command.startsWith("admin_diet")) { try { final StringTokenizer st = new StringTokenizer(command); st.nextToken(); if (st.nextToken().equalsIgnoreCase("on")) { activeChar.setDietMode(true); activeChar.sendMessage("Diet mode on"); } else if (st.nextToken().equalsIgnoreCase("off")) { activeChar.setDietMode(false); activeChar.sendMessage("Diet mode off"); } } catch (Exception ex) { if (activeChar.getDietMode()) { activeChar.setDietMode(false); activeChar.sendMessage("Diet mode off"); } else { activeChar.setDietMode(true); activeChar.sendMessage("Diet mode on"); } } finally { activeChar.refreshOverloaded(true); } AdminHtml.showAdminHtml(activeChar, "gm_menu.htm"); } else if (command.startsWith("admin_tradeoff")) { try { final String mode = command.substring(15); if (mode.equalsIgnoreCase("on")) { activeChar.setTradeRefusal(true); activeChar.sendMessage("Trade refusal enabled"); } else if (mode.equalsIgnoreCase("off")) { activeChar.setTradeRefusal(false); activeChar.sendMessage("Trade refusal disabled"); } } catch (Exception ex) { if (activeChar.getTradeRefusal()) { activeChar.setTradeRefusal(false); activeChar.sendMessage("Trade refusal disabled"); } else { activeChar.setTradeRefusal(true); activeChar.sendMessage("Trade refusal enabled"); } } AdminHtml.showAdminHtml(activeChar, "gm_menu.htm"); } else if (command.startsWith("admin_setconfig")) { final StringTokenizer st = new StringTokenizer(command); st.nextToken(); try { final String pName = st.nextToken(); final String pValue = st.nextToken(); if (Float.valueOf(pValue) == null) { activeChar.sendMessage("Invalid parameter!"); return false; } switch (pName) { case "RateXp": { Config.RATE_XP = Float.valueOf(pValue); break; } case "RateSp": { Config.RATE_SP = Float.valueOf(pValue); break; } case "RateDropSpoil": { Config.RATE_CORPSE_DROP_CHANCE_MULTIPLIER = Float.valueOf(pValue); break; } case "EnchantChanceElementStone": { Config.ENCHANT_CHANCE_ELEMENT_STONE = Float.valueOf(pValue); break; } case "EnchantChanceElementCrystal": { Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL = Float.valueOf(pValue); break; } case "EnchantChanceElementJewel": { Config.ENCHANT_CHANCE_ELEMENT_JEWEL = Float.valueOf(pValue); break; } case "EnchantChanceElementEnergy": { Config.ENCHANT_CHANCE_ELEMENT_ENERGY = Float.valueOf(pValue); break; } } activeChar.sendMessage("Config parameter " + pName + " set to " + pValue); } catch (Exception e) { activeChar.sendMessage("Usage: //setconfig "); } finally { showConfigPage(activeChar); } } else if (command.startsWith("admin_worldchat")) { final StringTokenizer st = new StringTokenizer(command); st.nextToken(); // admin_worldchat switch (st.hasMoreTokens() ? st.nextToken() : "") { case "shout": { final StringBuilder sb = new StringBuilder(); while (st.hasMoreTokens()) { sb.append(st.nextToken()); sb.append(" "); } final CreatureSay cs = new CreatureSay(activeChar, ChatType.WORLD, sb.toString()); L2World.getInstance().getPlayers().stream().filter(activeChar::isNotBlocked).forEach(cs::sendTo); break; } case "see": { final L2Object target = activeChar.getTarget(); if ((target == null) || !target.isPlayer()) { activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); break; } final L2PcInstance targetPlayer = target.getActingPlayer(); if (targetPlayer.getLevel() < Config.WORLD_CHAT_MIN_LEVEL) { activeChar.sendMessage("Your target's level is below the minimum: " + Config.WORLD_CHAT_MIN_LEVEL); break; } activeChar.sendMessage(targetPlayer.getName() + ": has " + targetPlayer.getWorldChatPoints() + " world chat points"); break; } case "set": { final L2Object target = activeChar.getTarget(); if ((target == null) || !target.isPlayer()) { activeChar.sendPacket(SystemMessageId.THAT_IS_AN_INCORRECT_TARGET); break; } final L2PcInstance targetPlayer = target.getActingPlayer(); if (targetPlayer.getLevel() < Config.WORLD_CHAT_MIN_LEVEL) { activeChar.sendMessage("Your target's level is below the minimum: " + Config.WORLD_CHAT_MIN_LEVEL); break; } if (!st.hasMoreTokens()) { activeChar.sendMessage("Incorrect syntax, use: //worldchat set "); break; } final String valueToken = st.nextToken(); if (!Util.isDigit(valueToken)) { activeChar.sendMessage("Incorrect syntax, use: //worldchat set "); break; } activeChar.sendMessage(targetPlayer.getName() + ": points changed from " + targetPlayer.getWorldChatPoints() + " to " + valueToken); targetPlayer.setWorldChatPoints(Integer.parseInt(valueToken)); targetPlayer.sendPacket(new ExWorldChatCnt(targetPlayer)); break; } default: { activeChar.sendMessage("Possible commands:"); activeChar.sendMessage(" - Send message: //worldchat shout "); activeChar.sendMessage(" - See your target's points: //worldchat see"); activeChar.sendMessage(" - Change your target's points: //worldchat set "); break; } } } else if (command.startsWith("admin_gmon")) { // TODO why is this empty? } return true; } @Override public String[] getAdminCommandList() { return ADMIN_COMMANDS; } private void showMainPage(L2PcInstance activeChar, String command) { int mode = 0; String filename = null; try { mode = Integer.parseInt(command.substring(11)); } catch (Exception e) { } switch (mode) { case 1: { filename = "main"; break; } case 2: { filename = "game"; break; } case 3: { filename = "effects"; break; } case 4: { filename = "server"; break; } case 5: { filename = "mods"; break; } case 6: { filename = "char"; break; } case 7: { filename = "gm"; break; } default: { filename = "main"; break; } } AdminHtml.showAdminHtml(activeChar, filename + "_menu.htm"); } private void showConfigPage(L2PcInstance activeChar) { final NpcHtmlMessage adminReply = new NpcHtmlMessage(); final StringBuilder replyMSG = new StringBuilder("L2J :: Config"); replyMSG.append("
Config Server Panel

"); replyMSG.append("
"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
Drop:
Rate EXP = " + Config.RATE_XP + "
Rate SP = " + Config.RATE_SP + "
Rate Drop Spoil = " + Config.RATE_CORPSE_DROP_CHANCE_MULTIPLIER + "
Enchant:
Enchant Element Stone = " + Config.ENCHANT_CHANCE_ELEMENT_STONE + "
Enchant Element Crystal = " + Config.ENCHANT_CHANCE_ELEMENT_CRYSTAL + "
Enchant Element Jewel = " + Config.ENCHANT_CHANCE_ELEMENT_JEWEL + "
Enchant Element Energy = " + Config.ENCHANT_CHANCE_ELEMENT_ENERGY + "
"); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); } }