Search in sources :

Example 11 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MaplePacketDecoder method doDecode.

@Override
protected boolean doDecode(IoSession session, IoBuffer in, ProtocolDecoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    if (client == null) {
        session.close(true);
        return false;
    }
    DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);
    if (decoderState == null) {
        decoderState = new DecoderState();
        session.setAttribute(DECODER_STATE_KEY, decoderState);
    }
    MapleAESOFB rcvdCrypto = client.getReceiveCrypto();
    if (in.remaining() >= 4 && decoderState.packetlength == -1) {
        int packetHeader = in.getInt();
        if (!rcvdCrypto.checkPacket(packetHeader)) {
            session.close(true);
            return false;
        }
        decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
    } else if (in.remaining() < 4 && decoderState.packetlength == -1) {
        return false;
    }
    if (in.remaining() >= decoderState.packetlength) {
        byte[] decryptedPacket = new byte[decoderState.packetlength];
        in.get(decryptedPacket, 0, decoderState.packetlength);
        decoderState.packetlength = -1;
        rcvdCrypto.crypt(decryptedPacket);
        MapleCustomEncryption.decryptData(decryptedPacket);
        out.write(decryptedPacket);
        return true;
    }
    return false;
}
Also used : MapleAESOFB(tools.MapleAESOFB) MapleClient(client.MapleClient)

Example 12 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class AbstractPlayerInteraction method givePartyItems.

public void givePartyItems(int id, short quantity, List<MapleCharacter> party) {
    for (MapleCharacter chr : party) {
        MapleClient cl = chr.getClient();
        if (quantity >= 0) {
            MapleInventoryManipulator.addById(cl, id, quantity);
        } else {
            MapleInventoryManipulator.removeById(cl, ItemConstants.getInventoryType(id), id, -quantity, true, false);
        }
        cl.announce(MaplePacketCreator.getShowItemGain(id, quantity, true));
    }
}
Also used : MapleCharacter(client.MapleCharacter) MapleClient(client.MapleClient)

Example 13 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class NPCScriptManager method dispose.

public void dispose(NPCConversationManager cm) {
    MapleClient c = cm.getClient();
    c.getPlayer().setCS(false);
    c.getPlayer().setNpcCooldown(System.currentTimeMillis());
    cms.remove(c);
    scripts.remove(c);
    if (cm.getScriptName() != null) {
        resetContext("npc/" + cm.getScriptName() + ".js", c);
    } else {
        resetContext("npc/" + cm.getNpc() + ".js", c);
    }
}
Also used : MapleClient(client.MapleClient)

Example 14 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MapleInventory method checkSpotsAndOwnership.

public static boolean checkSpotsAndOwnership(MapleCharacter chr, List<Pair<Item, MapleInventoryType>> items, List<Integer> typesSlotsUsed) {
    // assumption: no "UNDEFINED" or "EQUIPPED" items shall be tested here, all counts are >= 0 and item list to be checked is a legal one.
    Map<Long, Short> rcvItems = new LinkedHashMap<>();
    Map<Long, Byte> rcvTypes = new LinkedHashMap<>();
    Map<Long, String> rcvOwners = new LinkedHashMap<>();
    for (Pair<Item, MapleInventoryType> item : items) {
        Long itemHash = hashKey(item.left.getItemId(), item.left.getOwner());
        Short qty = rcvItems.get(itemHash);
        if (qty == null) {
            rcvItems.put(itemHash, item.left.getQuantity());
            rcvTypes.put(itemHash, item.right.getType());
            rcvOwners.put(itemHash, item.left.getOwner());
        } else {
            rcvItems.put(itemHash, (short) (qty + item.left.getQuantity()));
        }
    }
    MapleClient c = chr.getClient();
    for (Entry<Long, Short> it : rcvItems.entrySet()) {
        int itemType = rcvTypes.get(it.getKey()) - 1;
        int usedSlots = typesSlotsUsed.get(itemType);
        Long itemId = it.getKey() >> 32L;
        // System.out.print("inserting " + itemId.intValue() + " with type " + itemType + " qty " + it.getValue() + " owner '" + rcvOwners.get(it.getKey()) + "' current usedSlots:");
        // for(Integer i : typesSlotsUsed) System.out.print(" " + i);
        int result = MapleInventoryManipulator.checkSpaceProgressively(c, itemId.intValue(), it.getValue(), rcvOwners.get(it.getKey()), usedSlots);
        boolean hasSpace = ((result % 2) != 0);
        if (!hasSpace)
            return false;
        typesSlotsUsed.set(itemType, (result >> 1));
    }
    return true;
}
Also used : LinkedHashMap(java.util.LinkedHashMap) MapleClient(client.MapleClient)

Example 15 with MapleClient

use of client.MapleClient in project HeavenMS by ronancpl.

the class MapleServerHandler method sessionClosed.

@Override
public void sessionClosed(IoSession session) throws Exception {
    MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    if (client != null) {
        try {
            boolean inCashShop = false;
            if (client.getPlayer() != null) {
                inCashShop = client.getPlayer().getCashShop().isOpened();
            }
            client.disconnect(false, inCashShop);
        } catch (Throwable t) {
            FilePrinter.printError(FilePrinter.ACCOUNT_STUCK, t);
        } finally {
            session.close();
            session.removeAttribute(MapleClient.CLIENT_KEY);
        // client.empty();
        }
    }
    super.sessionClosed(session);
}
Also used : MapleClient(client.MapleClient)

Aggregations

MapleClient (client.MapleClient)21 Item (client.inventory.Item)4 Point (java.awt.Point)4 LinkedList (java.util.LinkedList)4 SpawnPoint (server.life.SpawnPoint)4 MapleInventoryType (client.inventory.MapleInventoryType)3 ArrayList (java.util.ArrayList)3 MapleAESOFB (tools.MapleAESOFB)3 MapleCharacter (client.MapleCharacter)2 SQLException (java.sql.SQLException)2 LinkedHashMap (java.util.LinkedHashMap)2 Pair (tools.Pair)2 MapleJob (client.MapleJob)1 Skill (client.Skill)1 Equip (client.inventory.Equip)1 ScrollResult (client.inventory.Equip.ScrollResult)1 MaplePet (client.inventory.MaplePet)1 ModifyInventory (client.inventory.ModifyInventory)1 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1