123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377 |
- /*
- * 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 <http://www.gnu.org/licenses/>.
- */
- package handlers.telnethandlers;
- import java.io.PrintWriter;
- import java.net.Socket;
- import java.sql.Connection;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- import java.util.NoSuchElementException;
- import java.util.StringTokenizer;
- import com.l2jserver.Config;
- import com.l2jserver.L2DatabaseFactory;
- import com.l2jserver.gameserver.handler.ITelnetHandler;
- import com.l2jserver.gameserver.model.L2World;
- import com.l2jserver.gameserver.model.actor.instance.L2PcInstance;
- import com.l2jserver.gameserver.model.item.instance.L2ItemInstance;
- import com.l2jserver.gameserver.model.itemcontainer.Inventory;
- import com.l2jserver.gameserver.network.SystemMessageId;
- import com.l2jserver.gameserver.network.serverpackets.CharInfo;
- import com.l2jserver.gameserver.network.serverpackets.ExBrExtraUserInfo;
- import com.l2jserver.gameserver.network.serverpackets.InventoryUpdate;
- import com.l2jserver.gameserver.network.serverpackets.SystemMessage;
- import com.l2jserver.gameserver.network.serverpackets.UserInfo;
- import com.l2jserver.gameserver.util.GMAudit;
- /**
- * @author UnAfraid
- */
- public class PlayerHandler implements ITelnetHandler
- {
- private final String[] _commands =
- {
- "kick",
- "give",
- "enchant",
- "jail",
- "unjail"
- };
-
- @Override
- public boolean useCommand(String command, PrintWriter _print, Socket _cSocket, int _uptime)
- {
- if (command.startsWith("kick"))
- {
- try
- {
- command = command.substring(5);
- L2PcInstance player = L2World.getInstance().getPlayer(command);
- if (player != null)
- {
- player.sendMessage("You are kicked by gm");
- player.logout();
- _print.println("Player kicked");
- }
- }
- catch (StringIndexOutOfBoundsException e)
- {
- _print.println("Please enter player name to kick");
- }
- }
- else if (command.startsWith("give"))
- {
- StringTokenizer st = new StringTokenizer(command.substring(5));
-
- try
- {
- L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
- int itemId = Integer.parseInt(st.nextToken());
- int amount = Integer.parseInt(st.nextToken());
-
- if (player != null)
- {
- L2ItemInstance item = player.getInventory().addItem("Status-Give", itemId, amount, null, null);
- InventoryUpdate iu = new InventoryUpdate();
- iu.addItem(item);
- player.sendPacket(iu);
- SystemMessage sm = SystemMessage.getSystemMessage(SystemMessageId.YOU_PICKED_UP_S1_S2);
- sm.addItemName(itemId);
- sm.addItemNumber(amount);
- player.sendPacket(sm);
- _print.println("ok");
- GMAudit.auditGMAction("Telnet Admin", "Give Item", player.getName(), "item: " + itemId + " amount: " + amount);
- }
- else
- {
- _print.println("Player not found");
- }
- }
- catch (Exception e)
- {
-
- }
- }
- else if (command.startsWith("enchant"))
- {
- StringTokenizer st = new StringTokenizer(command.substring(8), " ");
- int enchant = 0, itemType = 0;
-
- try
- {
- L2PcInstance player = L2World.getInstance().getPlayer(st.nextToken());
- itemType = Integer.parseInt(st.nextToken());
- enchant = Integer.parseInt(st.nextToken());
-
- switch (itemType)
- {
- case 1:
- itemType = Inventory.PAPERDOLL_HEAD;
- break;
- case 2:
- itemType = Inventory.PAPERDOLL_CHEST;
- break;
- case 3:
- itemType = Inventory.PAPERDOLL_GLOVES;
- break;
- case 4:
- itemType = Inventory.PAPERDOLL_FEET;
- break;
- case 5:
- itemType = Inventory.PAPERDOLL_LEGS;
- break;
- case 6:
- itemType = Inventory.PAPERDOLL_RHAND;
- break;
- case 7:
- itemType = Inventory.PAPERDOLL_LHAND;
- break;
- case 8:
- itemType = Inventory.PAPERDOLL_LEAR;
- break;
- case 9:
- itemType = Inventory.PAPERDOLL_REAR;
- break;
- case 10:
- itemType = Inventory.PAPERDOLL_LFINGER;
- break;
- case 11:
- itemType = Inventory.PAPERDOLL_RFINGER;
- break;
- case 12:
- itemType = Inventory.PAPERDOLL_NECK;
- break;
- case 13:
- itemType = Inventory.PAPERDOLL_UNDER;
- break;
- case 14:
- itemType = Inventory.PAPERDOLL_CLOAK;
- break;
- case 15:
- itemType = Inventory.PAPERDOLL_BELT;
- break;
- default:
- itemType = 0;
- }
-
- if (enchant > 65535)
- enchant = 65535;
- else if (enchant < 0)
- enchant = 0;
-
- boolean success = false;
-
- if (player != null && itemType > 0)
- {
- success = setEnchant(player, enchant, itemType);
- if (success)
- _print.println("Item enchanted successfully.");
- }
- else if (!success)
- _print.println("Item failed to enchant.");
- }
- catch (Exception e)
- {
-
- }
- }
- else if (command.startsWith("jail"))
- {
- StringTokenizer st = new StringTokenizer(command.substring(5));
- try
- {
- String name = st.nextToken();
- L2PcInstance playerObj = L2World.getInstance().getPlayer(name);
- int delay = 0;
- try
- {
- delay = Integer.parseInt(st.nextToken());
- }
- catch (NumberFormatException nfe)
- {
- }
- catch (NoSuchElementException nsee)
- {
- }
- // L2PcInstance playerObj = L2World.getInstance().getPlayer(player);
-
- if (playerObj != null)
- {
- playerObj.setPunishLevel(L2PcInstance.PunishLevel.JAIL, delay);
- _print.println("Character " + playerObj.getName() + " jailed for " + (delay > 0 ? delay + " minutes." : "ever!"));
- }
- else
- {
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
-
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
- statement.setInt(1, -114356);
- statement.setInt(2, -249645);
- statement.setInt(3, -2984);
- statement.setInt(4, L2PcInstance.PunishLevel.JAIL.value());
- statement.setLong(5, delay * 60000L);
- statement.setString(6, name);
-
- statement.execute();
- int count = statement.getUpdateCount();
- statement.close();
-
- if (count == 0)
- _print.println("Character not found!");
- else
- _print.println("Character " + name + " jailed for " + (delay > 0 ? delay + " minutes." : "ever!"));
- }
- catch (SQLException se)
- {
- _print.println("SQLException while jailing player");
- if (Config.DEBUG)
- se.printStackTrace();
- }
- finally
- {
- L2DatabaseFactory.close(con);
- }
- }
- }
- catch (NoSuchElementException nsee)
- {
- _print.println("Specify a character name.");
- }
- catch (Exception e)
- {
- if (Config.DEBUG)
- e.printStackTrace();
- }
- }
- else if (command.startsWith("unjail"))
- {
- StringTokenizer st = new StringTokenizer(command.substring(7));
- try
- {
- String name = st.nextToken();
- L2PcInstance playerObj = L2World.getInstance().getPlayer(name);
-
- if (playerObj != null)
- {
- playerObj.setPunishLevel(L2PcInstance.PunishLevel.NONE, 0);
- _print.println("Character " + playerObj.getName() + " removed from jail");
- }
- else
- {
- Connection con = null;
- try
- {
- con = L2DatabaseFactory.getInstance().getConnection();
-
- PreparedStatement statement = con.prepareStatement("UPDATE characters SET x=?, y=?, z=?, punish_level=?, punish_timer=? WHERE char_name=?");
- statement.setInt(1, 17836);
- statement.setInt(2, 170178);
- statement.setInt(3, -3507);
- statement.setInt(4, 0);
- statement.setLong(5, 0);
- statement.setString(6, name);
-
- statement.execute();
- int count = statement.getUpdateCount();
- statement.close();
-
- if (count == 0)
- _print.println("Character not found!");
- else
- _print.println("Character " + name + " set free.");
- }
- catch (SQLException se)
- {
- _print.println("SQLException while jailing player");
- if (Config.DEBUG)
- se.printStackTrace();
- }
- finally
- {
- L2DatabaseFactory.close(con);
- }
- }
- }
- catch (NoSuchElementException nsee)
- {
- _print.println("Specify a character name.");
- }
- catch (Exception e)
- {
- if (Config.DEBUG)
- e.printStackTrace();
- }
- }
- return false;
- }
-
- private boolean setEnchant(L2PcInstance activeChar, int ench, int armorType)
- {
- // now we need to find the equipped weapon of the targeted character...
- int curEnchant = 0; // display purposes only
- L2ItemInstance itemInstance = null;
-
- // only attempt to enchant if there is a weapon equipped
- L2ItemInstance parmorInstance = activeChar.getInventory().getPaperdollItem(armorType);
- if (parmorInstance != null && parmorInstance.getLocationSlot() == armorType)
- {
- itemInstance = parmorInstance;
- }
- else
- {
- // for bows/crossbows and double handed weapons
- parmorInstance = activeChar.getInventory().getPaperdollItem(Inventory.PAPERDOLL_RHAND);
- if (parmorInstance != null && parmorInstance.getLocationSlot() == Inventory.PAPERDOLL_RHAND)
- itemInstance = parmorInstance;
- }
-
- if (itemInstance != null)
- {
- curEnchant = itemInstance.getEnchantLevel();
-
- // set enchant value
- activeChar.getInventory().unEquipItemInSlot(armorType);
- itemInstance.setEnchantLevel(ench);
- activeChar.getInventory().equipItem(itemInstance);
-
- // send packets
- InventoryUpdate iu = new InventoryUpdate();
- iu.addModifiedItem(itemInstance);
- activeChar.sendPacket(iu);
- activeChar.broadcastPacket(new CharInfo(activeChar));
- activeChar.sendPacket(new UserInfo(activeChar));
- activeChar.broadcastPacket(new ExBrExtraUserInfo(activeChar));
-
- // informations
- activeChar.sendMessage("Changed enchantment of " + activeChar.getName() + "'s " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
- activeChar.sendMessage("Admin has changed the enchantment of your " + itemInstance.getItem().getName() + " from " + curEnchant + " to " + ench + ".");
-
- // log
- GMAudit.auditGMAction("TelnetAdministrator", "enchant", activeChar.getName(), itemInstance.getItem().getName() + "(" + itemInstance.getObjectId() + ")" + " from " + curEnchant + " to " + ench);
- return true;
- }
- return false;
- }
-
- @Override
- public String[] getCommandList()
- {
- return _commands;
- }
- }
|