当前位置: 首页>>代码示例>>Java>>正文


Java IoSession.getAttribute方法代码示例

本文整理汇总了Java中org.apache.mina.common.IoSession.getAttribute方法的典型用法代码示例。如果您正苦于以下问题:Java IoSession.getAttribute方法的具体用法?Java IoSession.getAttribute怎么用?Java IoSession.getAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.mina.common.IoSession的用法示例。


在下文中一共展示了IoSession.getAttribute方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getOrAddChannel

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
static MinaChannel getOrAddChannel(IoSession session, URL url, ChannelHandler handler) {
    if (session == null) {
        return null;
    }
    MinaChannel ret = (MinaChannel) session.getAttribute(CHANNEL_KEY);
    if (ret == null) {
        ret = new MinaChannel(session, url, handler);
        if (session.isConnected()) {
            MinaChannel old = (MinaChannel) session.setAttribute(CHANNEL_KEY, ret);
            if (old != null) {
                session.setAttribute(CHANNEL_KEY, old);
                ret = old;
            }
        }
    }
    return ret;
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:18,代码来源:MinaChannel.java

示例2: encode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        final byte[] input = ((MaplePacket) message).getBytes();
        final byte[] unencrypted = new byte[input.length];
        System.arraycopy(input, 0, unencrypted, 0, input.length);

        final byte[] ret = new byte[unencrypted.length + 4];

        final byte[] header = client.getSendCrypto().getPacketHeader(unencrypted.length);
        synchronized(client.getSendCrypto()){
            MapleCustomEncryption.encryptData(unencrypted);
            client.getSendCrypto().crypt(unencrypted);

            System.arraycopy(header, 0, ret, 0, 4);
            System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length);

            final ByteBuffer out_buffer = ByteBuffer.wrap(ret);
            out.write(out_buffer);
        }
    } else { // no client object created yet, send unencrypted (hello)
            out.write(ByteBuffer.wrap(((MaplePacket) message).getBytes()));
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:27,代码来源:MaplePacketEncoder.java

示例3: sessionClosed

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionClosed(final IoSession session) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        byte state = MapleClient.CHANGE_CHANNEL;
        if (!LoginServer.isShutdown() && client.getPlayer() != null) {
            state = client.getLoginState();
        }
        if (state != MapleClient.CHANGE_CHANNEL) {
            if (System.currentTimeMillis() - lastDC < 60000) { //within the minute
                numDC++;
                if (numDC > 100) { //100+ people have dc'd in minute in channelserver
                    System.out.println("Writing log...");
                    numDC = 0;
                    lastDC = System.currentTimeMillis(); // intentionally place here
                }
            } else {
                numDC = 0;
                lastDC = System.currentTimeMillis(); // intentionally place here
            }
        }
        
        session.close();
        client.disconnect(true, false);
        session.removeAttribute(MapleClient.CLIENT_KEY);
    }
    super.sessionClosed(session);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:30,代码来源:MapleServerHandler.java

示例4: sessionIdle

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        // client.sendPing();
    }
    super.sessionIdle(session, status);
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:10,代码来源:MapleServerHandler.java

示例5: encode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void encode(final IoSession session, final Object message, final ProtocolEncoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (client != null) {
        final MapleAESOFB send_crypto = client.getSendCrypto();

        final byte[] inputInitialPacket = ((byte[]) message);
        final byte[] unencrypted = new byte[inputInitialPacket.length];
        System.arraycopy(inputInitialPacket, 0, unencrypted, 0, inputInitialPacket.length); // Copy the input > "unencrypted"
        final byte[] ret = new byte[unencrypted.length + 4]; // Create new bytes with length = "unencrypted" + 4

        final Lock mutex = client.getLock();
        mutex.lock();
        try {
            final byte[] header = send_crypto.getPacketHeader(unencrypted.length);
            // MapleCustomEncryption.encryptData(unencrypted); // Encrypting Data
            send_crypto.crypt(unencrypted); // Crypt it with IV
            System.arraycopy(header, 0, ret, 0, 4); // Copy the header > "Ret", first 4 bytes
        } finally {
            mutex.unlock();
        }
        System.arraycopy(unencrypted, 0, ret, 4, unencrypted.length); // Copy the unencrypted > "ret"
        out.write(ByteBuffer.wrap(ret));
    } else { // no client object created yet, send unencrypted (hello)
        out.write(ByteBuffer.wrap((byte[]) message));
    }
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:29,代码来源:MaplePacketEncoder.java

示例6: doDecode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
protected boolean doDecode(IoSession session, ByteBuffer in, ProtocolDecoderOutput out) throws Exception {
    final DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);

    /*	if (decoderState == null) {
     decoderState = new DecoderState();
     session.setAttribute(DECODER_STATE_KEY, decoderState);
     }*/
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);

    if (decoderState != null) {
    	if (decoderState.packetlength == -1) {
            if (in.remaining() >= 4) {
                final int packetHeader = in.getInt();
                if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
                    session.close();
                    return false;
                }
                decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
            } else {
                return false;
            }
        }
        if (in.remaining() >= decoderState.packetlength) {
            final byte decryptedPacket[] = new byte[decoderState.packetlength];
            in.get(decryptedPacket, 0, decoderState.packetlength);
            decoderState.packetlength = -1;

            client.getReceiveCrypto().crypt(decryptedPacket);
            // MapleCustomEncryption.decryptData(decryptedPacket);
            out.write(decryptedPacket);
            return true;
        }
    }
    return false;
}
 
开发者ID:ergothvs,项目名称:Lucid2.0,代码行数:37,代码来源:MaplePacketDecoder.java

示例7: doDecode

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
protected boolean doDecode(final IoSession session, final ByteBuffer in, final ProtocolDecoderOutput out) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    DecoderState decoderState = (DecoderState) session.getAttribute(DECODER_STATE_KEY);

    if (decoderState == null) {
        decoderState = new DecoderState();
        session.setAttribute(DECODER_STATE_KEY, decoderState);
    }

    if (in.remaining() >= 4 && decoderState.packetlength == -1) {
        final int packetHeader = in.getInt();
        if (!client.getReceiveCrypto().checkPacket(packetHeader)) {
            System.err.println(MapleClient.getLogMessage(client, "Client failed packet check -> disconnecting"));
            session.close();
            return false;
        }
        decoderState.packetlength = MapleAESOFB.getPacketLength(packetHeader);
    } else if (in.remaining() < 4 && decoderState.packetlength == -1) {
        //System.err.println("decode... not enough data");
        return false;
    }

    if (in.remaining() >= decoderState.packetlength) {
        final byte[] decryptedPacket = new byte[decoderState.packetlength];
        in.get(decryptedPacket, 0, decoderState.packetlength);
        decoderState.packetlength = -1;

        client.getReceiveCrypto().crypt(decryptedPacket);
        MapleCustomEncryption.decryptData(decryptedPacket);
        out.write(decryptedPacket);

        return true;
    } else {
        //System.err.println("decode... not enough data to decode (need " + decoderState.packetlength + ")");
        return false;
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:39,代码来源:MaplePacketDecoder.java

示例8: sessionClosed

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionClosed(final IoSession session) throws Exception {
    synchronized (session) {
        final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
        if (client != null) {
            client.disconnect();
            LoginWorker.getInstance().deregisterClient(client);
            session.removeAttribute(MapleClient.CLIENT_KEY);
        }
    }
    super.sessionClosed(session);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:13,代码来源:MapleServerHandler.java

示例9: sessionIdle

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void sessionIdle(final IoSession session, final IdleStatus status) throws Exception {
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    /*
    if (client != null && client.getPlayer() != null) {
        System.out.println("Player " + client.getPlayer().getName() + " went idle.");
    }
    */
    if (client != null) client.sendPing();
    super.sessionIdle(session, status);
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:12,代码来源:MapleServerHandler.java

示例10: messageReceived

import org.apache.mina.common.IoSession; //导入方法依赖的package包/类
@Override
public void messageReceived(final IoSession session, final Object message) throws Exception {
    final byte[] content = (byte[]) message;
    final SeekableLittleEndianAccessor slea =
        new GenericSeekableLittleEndianAccessor(
            new ByteArrayByteStream(content)
        );
    final short packetId = slea.readShort();
    final MapleClient client = (MapleClient) session.getAttribute(MapleClient.CLIENT_KEY);
    final MaplePacketHandler packetHandler = processor.getHandler(packetId);
    //
    client.pongReceived();
    //
    //if (log.isTraceEnabled() || log.isInfoEnabled()) {
        //String from = "";
        //if (client.getPlayer() != null) {
            //from = "from " + client.getPlayer().getName() + " ";
        //}
        //if (packetHandler == null) {
            //log.info("Got unhandled Message {} ({}) {}\n{}", new Object[]{from, content.length, HexTool.toString(content), HexTool.toStringFromAscii(content)});
        //}
    //}
    if (packetHandler != null && packetHandler.validateState(client)) {
        try {
            //if (trace) {
                //String from = "";
                //if (client.getPlayer() != null) {
                    //from = "from " + client.getPlayer().getName() + " ";
                //}
            //log.info("Got Message {}handled by {} ({}) {}\n{}", new Object[] { from, packetHandler.getClass().getSimpleName(), content.length, HexTool.toString(content), HexTool.toStringFromAscii(content) });
            //}
            //System.out.println(packetHandler.getClass().getSimpleName());
            packetHandler.handlePacket(slea, client);
        } catch (final Throwable t) {
            if (!packetHandler.getClass().getName().contains("ItemPickupHandler")) {
                System.err.println(
                    "Exception during processing packet: " +
                        packetHandler.getClass().getName() +
                        ":"
                );
                t.printStackTrace();
            }
        }
    }
}
 
开发者ID:NoetherEmmy,项目名称:intransigentms,代码行数:46,代码来源:MapleServerHandler.java


注:本文中的org.apache.mina.common.IoSession.getAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。