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;
}
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));
}
}
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);
}
}
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;
}
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);
}
Aggregations