Search in sources :

Example 11 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class GeneralChatHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    String s = slea.readMapleAsciiString();
    MapleCharacter chr = c.getPlayer();
    if (chr.getAutobanManager().getLastSpam(7) + 200 > System.currentTimeMillis()) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (s.length() > Byte.MAX_VALUE && !chr.isGM()) {
        AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit in General Chat.");
        FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to send text with length of " + s.length() + "\r\n");
        c.disconnect(true, false);
        return;
    }
    char heading = s.charAt(0);
    if (heading == '!' || heading == '@') {
        String[] sp = s.split(" ");
        sp[0] = sp[0].toLowerCase().substring(1);
        if (Commands.executeSolaxiaPlayerCommand(c, sp, heading)) {
            String command = "";
            for (String used : sp) {
                command += used + " ";
            }
            SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy HH:mm");
            FilePrinter.print(FilePrinter.USED_COMMANDS, c.getPlayer().getName() + " used: " + heading + command + "on " + sdf.format(Calendar.getInstance().getTime()) + "\r\n");
        }
    } else if (heading != '/') {
        int show = slea.readByte();
        if (chr.getMap().isMuted() && !chr.isGM()) {
            chr.dropMessage(5, "The map you are in is currently muted. Please try again later.");
            return;
        }
        if (!chr.isHidden()) {
            chr.getMap().broadcastMessage(MaplePacketCreator.getChatText(chr.getId(), s, chr.getWhiteChat(), show));
        } else {
            chr.getMap().broadcastGMMessage(MaplePacketCreator.getChatText(chr.getId(), s, chr.getWhiteChat(), show));
        }
        chr.getAutobanManager().spam(7);
    }
}
Also used : MapleCharacter(client.MapleCharacter) SimpleDateFormat(java.text.SimpleDateFormat)

Example 12 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class GiveFameHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter target = (MapleCharacter) c.getPlayer().getMap().getMapObject(slea.readInt());
    int mode = slea.readByte();
    int famechange = 2 * mode - 1;
    MapleCharacter player = c.getPlayer();
    if (target == null || target.getId() == player.getId() || player.getLevel() < 15) {
        return;
    } else if (famechange != 1 && famechange != -1) {
        AutobanFactory.PACKET_EDIT.alert(c.getPlayer(), c.getPlayer().getName() + " tried to packet edit fame.");
        FilePrinter.printError(FilePrinter.EXPLOITS + c.getPlayer().getName() + ".txt", c.getPlayer().getName() + " tried to fame hack with famechange " + famechange + "\r\n");
        c.disconnect(true, false);
        return;
    }
    FameStatus status = player.canGiveFame(target);
    if (status == FameStatus.OK || player.isGM()) {
        if (Math.abs(target.getFame() + famechange) < 30001) {
            target.addFame(famechange);
            target.updateSingleStat(MapleStat.FAME, target.getFame());
        }
        if (!player.isGM()) {
            player.hasGivenFame(target);
        }
        c.announce(MaplePacketCreator.giveFameResponse(mode, target.getName(), target.getFame()));
        target.getClient().announce(MaplePacketCreator.receiveFame(mode, player.getName()));
    } else {
        c.announce(MaplePacketCreator.giveFameErrorResponse(status == FameStatus.NOT_TODAY ? 3 : 4));
    }
}
Also used : MapleCharacter(client.MapleCharacter) FameStatus(client.MapleCharacter.FameStatus)

Example 13 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class HealOvertimeHandler method handlePacket.

public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    AutobanManager abm = chr.getAutobanManager();
    int timestamp = slea.readInt();
    abm.setTimestamp(0, timestamp, 3);
    slea.skip(4);
    short healHP = slea.readShort();
    if (healHP != 0) {
        if ((abm.getLastSpam(0) + 1500) > timestamp)
            AutobanFactory.FAST_HP_HEALING.addPoint(abm, "Fast hp healing");
        int abHeal = 140;
        // Sleepywood sauna and showa spa...
        if (chr.getMapId() == 105040401 || chr.getMapId() == 105040402 || chr.getMapId() == 809000101 || chr.getMapId() == 809000201)
            abHeal += 40;
        if (healHP > abHeal) {
            AutobanFactory.HIGH_HP_HEALING.autoban(chr, "Healing: " + healHP + "; Max is " + abHeal + ".");
            return;
        }
        chr.addHP(healHP);
        chr.getMap().broadcastMessage(chr, MaplePacketCreator.showHpHealed(chr.getId(), healHP), false);
        chr.checkBerserk(chr.isHidden());
        abm.spam(0, timestamp);
    }
    short healMP = slea.readShort();
    if (healMP != 0 && healMP < 1000) {
        if ((abm.getLastSpam(1) + 1500) > timestamp)
            AutobanFactory.FAST_MP_HEALING.addPoint(abm, "Fast mp healing");
        chr.addMP(healMP);
        abm.spam(1, timestamp);
    }
}
Also used : MapleCharacter(client.MapleCharacter) AutobanManager(client.autoban.AutobanManager)

Example 14 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class InventoryMergeHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(2, slea.readInt(), 3);
    MapleInventoryType inventoryType = MapleInventoryType.getByType(slea.readByte());
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    MapleInventory inventory = c.getPlayer().getInventory(inventoryType);
    // ------------------- RonanLana's SLOT MERGER -----------------
    MapleItemInformationProvider ii = MapleItemInformationProvider.getInstance();
    Item srcItem, dstItem;
    for (short dst = 1; dst <= inventory.getSlotLimit(); dst++) {
        dstItem = inventory.getItem(dst);
        if (dstItem == null)
            continue;
        for (short src = (short) (dst + 1); src <= inventory.getSlotLimit(); src++) {
            srcItem = inventory.getItem(src);
            if (srcItem == null)
                continue;
            if (dstItem.getItemId() != srcItem.getItemId())
                continue;
            if (dstItem.getQuantity() == ii.getSlotMax(c, inventory.getItem(dst).getItemId()))
                break;
            MapleInventoryManipulator.move(c, inventoryType, src, dst);
        }
    }
    // ------------------------------------------------------------
    inventory = c.getPlayer().getInventory(inventoryType);
    boolean sorted = false;
    while (!sorted) {
        short freeSlot = inventory.getNextFreeSlot();
        if (freeSlot != -1) {
            short itemSlot = -1;
            for (short i = (short) (freeSlot + 1); i <= inventory.getSlotLimit(); i = (short) (i + 1)) {
                if (inventory.getItem(i) != null) {
                    itemSlot = i;
                    break;
                }
            }
            if (itemSlot > 0) {
                MapleInventoryManipulator.move(c, inventoryType, itemSlot, freeSlot);
            } else {
                sorted = true;
            }
        } else {
            sorted = true;
        }
    }
    c.announce(MaplePacketCreator.finishedSort(inventoryType.getType()));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) MapleInventoryType(client.inventory.MapleInventoryType) MapleItemInformationProvider(server.MapleItemInformationProvider) MapleInventory(client.inventory.MapleInventory)

Example 15 with MapleCharacter

use of client.MapleCharacter in project HeavenMS by ronancpl.

the class InventorySortHandler method handlePacket.

@Override
public final void handlePacket(SeekableLittleEndianAccessor slea, MapleClient c) {
    MapleCharacter chr = c.getPlayer();
    chr.getAutobanManager().setTimestamp(3, slea.readInt(), 3);
    byte inventoryType = slea.readByte();
    if (!ServerConstants.USE_ITEM_SORT) {
        c.announce(MaplePacketCreator.enableActions());
        return;
    }
    if (inventoryType < 1 || inventoryType > 5) {
        c.disconnect(false, false);
        return;
    }
    MapleInventory inventory = chr.getInventory(MapleInventoryType.getByType(inventoryType));
    ArrayList<Item> itemarray = new ArrayList<>();
    List<ModifyInventory> mods = new ArrayList<>();
    for (short i = 1; i <= inventory.getSlotLimit(); i++) {
        Item item = inventory.getItem(i);
        if (item != null) {
            itemarray.add((Item) item.copy());
        }
    }
    for (Item item : itemarray) {
        inventory.removeSlot(item.getPosition());
        mods.add(new ModifyInventory(3, item));
    }
    int invTypeCriteria = (MapleInventoryType.getByType(inventoryType) == MapleInventoryType.EQUIP) ? 3 : 1;
    int sortCriteria = (ServerConstants.USE_ITEM_SORT_BY_NAME == true) ? 2 : 0;
    PairedQuicksort pq = new PairedQuicksort(itemarray, sortCriteria, invTypeCriteria);
    for (Item item : itemarray) {
        inventory.addItem(item);
        // to prevent crashes
        mods.add(new ModifyInventory(0, item.copy()));
    }
    itemarray.clear();
    c.announce(MaplePacketCreator.modifyInventory(true, mods));
    c.announce(MaplePacketCreator.finishedSort2(inventoryType));
    c.announce(MaplePacketCreator.enableActions());
}
Also used : Item(client.inventory.Item) MapleCharacter(client.MapleCharacter) ArrayList(java.util.ArrayList) MapleInventory(client.inventory.MapleInventory) ModifyInventory(client.inventory.ModifyInventory)

Aggregations

MapleCharacter (client.MapleCharacter)163 Point (java.awt.Point)32 SQLException (java.sql.SQLException)22 Item (client.inventory.Item)21 Connection (java.sql.Connection)15 PreparedStatement (java.sql.PreparedStatement)15 MapleMonster (server.life.MapleMonster)15 MapleMapObject (server.maps.MapleMapObject)15 DatabaseConnection (tools.DatabaseConnection)15 MapleMap (server.maps.MapleMap)14 ArrayList (java.util.ArrayList)13 Skill (client.Skill)12 SpawnPoint (server.life.SpawnPoint)12 LinkedList (java.util.LinkedList)11 MapleInventory (client.inventory.MapleInventory)10 World (net.server.world.World)10 MapleStatEffect (server.MapleStatEffect)10 MapleInventoryType (client.inventory.MapleInventoryType)9 ResultSet (java.sql.ResultSet)9 MapleItemInformationProvider (server.MapleItemInformationProvider)9