/* * 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 2, 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, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA * 02111-1307, USA. * * [URL]http://www.gnu.org/copyleft/gpl.html[/URL] */ package net.sf.l2j.gameserver.handler.admincommandhandlers; import java.util.StringTokenizer; import net.sf.l2j.Config; import net.sf.l2j.gameserver.GmListTable; import net.sf.l2j.gameserver.ItemTable; import net.sf.l2j.gameserver.NpcTable; import net.sf.l2j.gameserver.SkillTable; import net.sf.l2j.gameserver.SkillTreeTable; import net.sf.l2j.gameserver.TeleportLocationTable; import net.sf.l2j.gameserver.cache.HtmCache; import net.sf.l2j.gameserver.handler.IAdminCommandHandler; import net.sf.l2j.gameserver.instancemanager.ZoneManager; import net.sf.l2j.gameserver.model.L2Multisell; import net.sf.l2j.gameserver.model.L2World; import net.sf.l2j.gameserver.model.actor.instance.L2PcInstance; import net.sf.l2j.gameserver.serverpackets.ItemList; import net.sf.l2j.gameserver.serverpackets.NpcHtmlMessage; import net.sf.l2j.gameserver.serverpackets.PlaySound; import net.sf.l2j.gameserver.serverpackets.ServerBasePacket; import net.sf.l2j.gameserver.serverpackets.SignsSky; import net.sf.l2j.gameserver.serverpackets.SunRise; import net.sf.l2j.gameserver.serverpackets.SunSet; import net.sf.l2j.gameserver.serverpackets.SystemMessage; /** * This class handles following admin commands: * - admin = shows menu * * @version $Revision: 1.3.2.1.2.4 $ $Date: 2005/04/11 10:06:06 $ */ public class AdminAdmin implements IAdminCommandHandler { private static String[] _adminCommands = {"admin_admin","admin_play_sounds","admin_play_sound", "admin_gmliston","admin_gmlistoff","admin_silence", "admin_atmosphere","admin_diet","admin_tradeoff", "admin_reload", "admin_set", "admin_giveitem"}; private static final int REQUIRED_LEVEL = Config.GM_MENU; public boolean useAdminCommand(String command, L2PcInstance activeChar) { if (!Config.ALT_PRIVILEGES_ADMIN) if (!(checkLevel(activeChar.getAccessLevel()) && activeChar.isGM())) return false; if (command.equals("admin_admin")) showMainPage(activeChar); if (command.equals("admin_play_sounds")) { AdminHelpPage.showHelpPage(activeChar, "songs/songs.htm"); } else if (command.startsWith("admin_play_sounds")) { try { AdminHelpPage.showHelpPage(activeChar, "songs/songs"+command.substring(17)+".htm"); } catch (StringIndexOutOfBoundsException e) { } } else if (command.startsWith("admin_play_sound")) { try { playAdminSound(activeChar,command.substring(17)); } catch (StringIndexOutOfBoundsException e) { } } else if(command.startsWith("admin_gmliston")) { GmListTable.getInstance().addGm(activeChar); activeChar.sendMessage("Registerd into gm list"); } else if(command.startsWith("admin_gmlistoff")) { GmListTable.getInstance().deleteGm(activeChar); activeChar.sendMessage("Removed from gm list"); } else if(command.startsWith("admin_silence")) { if(activeChar.getMessageRefusal()) // already in message refusal mode { activeChar.setMessageRefusal(false); SystemMessage _sm = new SystemMessage(SystemMessage.MESSAGE_ACCEPTANCE_MODE); activeChar.sendPacket(_sm); } else { activeChar.setMessageRefusal(true); SystemMessage _sm = new SystemMessage(SystemMessage.MESSAGE_REFUSAL_MODE); activeChar.sendPacket(_sm); } } else if(command.startsWith("admin_atmosphere")) { try { StringTokenizer st = new StringTokenizer(command); st.nextToken(); String type = st.nextToken(); String state = st.nextToken(); adminAtmosphere(type,state,activeChar); } catch(Exception ex) { } } else if(command.startsWith("admin_diet")) { try { StringTokenizer st = new StringTokenizer(command); st.nextToken(); if(st.nextToken().equalsIgnoreCase("on")) { activeChar.setDietMode(true); activeChar.refreshOverloaded(); 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.sendMessage("Diet mode currently on"); else activeChar.sendMessage("Diet mode currently off"); } } else if(command.startsWith("admin_tradeoff")) { try { StringTokenizer st = new StringTokenizer(command); st.nextToken(); if(st.nextToken().equalsIgnoreCase("on")) { activeChar.setTradeRefusal(true); activeChar.sendMessage("tradeoff enabled"); } else if(st.nextToken().equalsIgnoreCase("off")) { activeChar.setTradeRefusal(false); activeChar.sendMessage("tradeoff disabled"); } } catch(Exception ex) { if(activeChar.getTradeRefusal()) activeChar.sendMessage("tradeoff currently enabled"); else activeChar.sendMessage("tradeoff currently disabled"); } } else if(command.startsWith("admin_reload")) { StringTokenizer st = new StringTokenizer(command); st.nextToken(); try { String type = st.nextToken(); if(type.equals("multisell")) { L2Multisell.getInstance().reload(); activeChar.sendMessage("multisell reloaded"); } else if(type.startsWith("teleport")) { TeleportLocationTable.getInstance().reloadAll(); activeChar.sendMessage("teleport location table reloaded"); } else if(type.startsWith("skill")) { SkillTable.getInstance().reload(); activeChar.sendMessage("skills reloaded"); } else if(type.equals("npc")) { NpcTable.getInstance().reloadAllNpc(); activeChar.sendMessage("npcs reloaded"); } else if(type.startsWith("htm")) { HtmCache.getInstance().reload(); activeChar.sendMessage("Cache[HTML]: " + HtmCache.getInstance().getMemoryUsage() + " megabytes on " + HtmCache.getInstance().getLoadedFiles() + " files loaded"); } else if(type.startsWith("item")) { ItemTable.getInstance().reload(); activeChar.sendMessage("Item templates reloaded"); } else if(type.startsWith("zone")) { ZoneManager.getInstance().reloadAll(); activeChar.sendMessage("Zones reloaded."); } } catch(Exception e) { activeChar.sendMessage("Usage: //reload "); } } else if(command.startsWith("admin_set")) { StringTokenizer st = new StringTokenizer(command); st.nextToken(); try { String[] parameter = st.nextToken().split("="); String pName = parameter[0].trim(); String pValue = parameter[1].trim(); if (Config.setParameterValue(pName, pValue)) activeChar.sendMessage("parameter set succesfully"); else activeChar.sendMessage("Invalid parameter!"); } catch(Exception e) { activeChar.sendMessage("Usage: //set parameter=value"); } } //GIVEMADD command by morrow, //giveitem id# #ofitems else if(command.startsWith("admin_giveitem")) { try { String targetName = command.substring(13); String val = command.substring(17); StringTokenizer st = new StringTokenizer(val); if (st.countTokens()== 2) { L2PcInstance player = L2World.getInstance().getPlayer(targetName); String id = st.nextToken(); int idval = Integer.parseInt(id); String num = st.nextToken(); int numval = Integer.parseInt(num); giveItem(player,idval,numval); } else if (st.countTokens()== 1) { L2PcInstance player = L2World.getInstance().getPlayer(targetName); String id = st.nextToken(); int idval = Integer.parseInt(id); giveItem(player,idval,1); } } catch (StringIndexOutOfBoundsException e) { SystemMessage sm = new SystemMessage(614); sm.addString("Error while creating item."); activeChar.sendPacket(sm); } } //---------------------- return true; } public String[] getAdminCommandList() { return _adminCommands; } private boolean checkLevel(int level) { return (level >= REQUIRED_LEVEL); } /** * * @param type - atmosphere type (signssky,sky) * @param state - atmosphere state(night,day) */ //---------for //giveitem private void giveItem(L2PcInstance player, int id, int num) { player.getInventory().addItem("Admin", id, num, player, null); ItemList il = new ItemList(player, true); player.sendPacket(il); SystemMessage sm = new SystemMessage(614); sm.addString("An Admin has spawned " + num + " item(s) number " + id + " in your inventory."); player.sendPacket(sm); } //------------- public void adminAtmosphere(String type, String state, L2PcInstance activeChar) { ServerBasePacket packet = null; if(type.equals("signsky")) { if(state.equals("dawn")) { packet = new SignsSky(2); } else if(state.equals("dusk")) { packet = new SignsSky(1); } } else if(type.equals("sky")) { if(state.equals("night")) { packet = new SunSet(); } else if(state.equals("day")) { packet = new SunRise(); } } else { SystemMessage sm = new SystemMessage(614); sm.addString("Only sky and signsky atmosphere type allowed, damn u!"); activeChar.sendPacket(sm); } if(packet != null) { for (L2PcInstance player : L2World.getInstance().getAllPlayers()) { player.sendPacket(packet); } } } public void playAdminSound(L2PcInstance activeChar, String sound) { PlaySound _snd = new PlaySound(1,sound,0,0,0,0,0); activeChar.sendPacket(_snd); activeChar.broadcastPacket(_snd); showMainPage(activeChar); SystemMessage _sm = new SystemMessage(614); _sm.addString("Playing "+sound+"."); activeChar.sendPacket(_sm); } public void showMainPage(L2PcInstance activeChar) { NpcHtmlMessage adminReply = new NpcHtmlMessage(5); StringBuffer replyMSG = new StringBuffer(""); replyMSG.append("
L2J Admin Panel

"); replyMSG.append("
"); replyMSG.append(""); replyMSG.append("

"); replyMSG.append("
Name / Karma / Ench 0-65535:
"); replyMSG.append("

"); replyMSG.append("
"); replyMSG.append("
"); replyMSG.append("
"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("
"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("

"); replyMSG.append(""); replyMSG.append("
"); replyMSG.append("

"); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append(""); replyMSG.append("



"); replyMSG.append("Server Software: Server software running L2J version 3.0.1 nightly created by L2Chef and the L2J team."); replyMSG.append(""); adminReply.setHtml(replyMSG.toString()); activeChar.sendPacket(adminReply); } }