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


Java MessageBuf.add方法代码示例

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


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

示例1: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf, MessageBuf<Object> out) throws Exception {
    if (state == State.READ_OPCODE) {
        if (!buf.isReadable())
            return;

        opcode = (buf.readUnsignedByte() - cipher.nextInt()) & 0xFF;
        size = SIZES[opcode];

        if (size == -3) {
            logger.info("invalid opcode: " + opcode);
            ctx.close();
            return;
        }

        variable = size == -1;
        state = variable ? State.READ_SIZE : State.READ_PAYLOAD;
    }

    if (state == State.READ_SIZE) {
        if (!buf.isReadable())
            return;

        size = buf.readUnsignedByte();
        state = State.READ_PAYLOAD;
    }

    if (state == State.READ_PAYLOAD) {
        if (buf.readableBytes() < size)
            return;

        ByteBuf payload = buf.readBytes(size);
        state = State.READ_OPCODE;

        out.add(new GameFrame(opcode, variable ? Type.VARIABLE_BYTE : Type.FIXED, payload));
    }
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:38,代码来源:GameFrameDecoder.java

示例2: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void decode(ChannelHandlerContext ctx, GameFrame frame, MessageBuf<Object> out) throws IOException {
    MessageDecoder<Message> decoder = (MessageDecoder<Message>) codecs.get(frame.getOpcode());

    if (decoder == null) {
        logger.warn("No decoder for packet id " + frame.getOpcode() + ".");
        return;
    }

    out.add(decoder.decode(frame));
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:13,代码来源:GameMessageDecoder.java

示例3: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf, MessageBuf<Object> out) {
	if (buf.readableBytes() < 4)
		return;

	out.add(new WorldHandshakeMessage(buf.readInt()));
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:8,代码来源:WorldListDecoder.java

示例4: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, String str, MessageBuf<Object> out) throws Exception {
    if (!str.startsWith("JAGGRAB ")) {
        return;
    }
    out.add(new JaggrabRequest(str.substring(8)));
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:8,代码来源:JaggrabDecoder.java

示例5: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf, MessageBuf<Object> out) throws Exception {
	if (buf.readableBytes() < 4)
		return;

	if (state == State.READ_VERSION) {
		state = State.READ_REQUEST;
		out.add(new UpdateVersionMessage(buf.readInt()));
	} else {
		int opcode = buf.readUnsignedByte();
		if (opcode == 0 || opcode == 1) {
			int type = buf.readUnsignedByte();
			int file = buf.readUnsignedShort();
			out.add(new FileRequest(opcode == 1, type, file));
		} else if (opcode == 4) {
			int key = buf.readUnsignedByte();
			buf.readerIndex(buf.readerIndex() + 2);
			out.add(new UpdateEncryptionMessage(key));
		} else {
			/*
			 * other unused opcodes:
			 *
			 * 2 - logged in
			 * 3 - logged out
			 * 6 - connection initiated
			 * 7 - connection done
			 */
			buf.readerIndex(buf.readerIndex() + 3);
			return; /* TODO print a warning or add support for reading these opcodes? */
		}
	}
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:33,代码来源:UpdateDecoder.java

示例6: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf, MessageBuf<Object> out) throws IOException {
	if (state == State.READ_SIZE) {
		if (!buf.isReadable())
			return;

		state = State.READ_PAYLOAD;
		size = buf.readUnsignedByte();
	}

	if (state == State.READ_PAYLOAD) {
		if (buf.readableBytes() < size)
			return;

		int encryptedSize = buf.readUnsignedByte();
		if (encryptedSize != size - 1)
			throw new IOException("Encrypted size mismatch.");

		ByteBuf secureBuffer = ByteBufUtils.rsa(buf.readBytes(encryptedSize), RsaKeySet.MODULUS, RsaKeySet.PRIVATE_KEY);
		int encryptedType = secureBuffer.readUnsignedByte();
		if (encryptedType != 10)
			throw new IOException("Invalid encrypted block type.");

		secureBuffer.readUnsignedShort();
		int version = secureBuffer.readUnsignedShort();
		String username = Base37Utils.decodeBase37(secureBuffer.readLong());
		secureBuffer.readInt();
		String password = ByteBufUtils.readString(secureBuffer);
		secureBuffer.readInt();

		out.add(new AutoLoginRequest(version, username, password));
	}
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:34,代码来源:AutoLoginDecoder.java

示例7: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buffer, MessageBuf<Object> out) {
	if (state == State.READ_OPCODE) {
		if (!buffer.isReadable())
			return;

		state = State.READ_LENGTH;
		opcode = buffer.readUnsignedByte();
	}

	if (state == State.READ_LENGTH) {
		if (buffer.readableBytes() < 2)
			return;

		state = State.READ_PAYLOAD;
		len = buffer.readUnsignedShort();
	}

	if (state == State.READ_PAYLOAD) {
		if (buffer.readableBytes() < len)
			return;

		state = State.READ_OPCODE;
		ByteBuf payload = buffer.readBytes(len);
		out.add(new LoginFrame(opcode, payload));
	}
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:28,代码来源:LoginFrameDecoder.java

示例8: encode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public void encode(ChannelHandlerContext ctx, Message message, MessageBuf<Object> out) throws IOException {
	MessageEncoder<Message> encoder = (MessageEncoder<Message>) codecs.get(message.getClass());
	out.add(encoder.encode(ctx.alloc(), message));
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:7,代码来源:GameMessageEncoder.java

示例9: decode

import io.netty.buffer.MessageBuf; //导入方法依赖的package包/类
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buf, MessageBuf<Object> out) throws IOException {
	if (state == State.READ_HEADER) {
		if (buf.readableBytes() < 4)
			return;

		state = State.READ_PAYLOAD;
		hash = buf.readUnsignedByte();
		type = buf.readUnsignedByte();
		size = buf.readUnsignedShort();

		if (type != 16 && type != 18)
			throw new IOException("Invalid login type.");
	}

	if (state == State.READ_PAYLOAD) {
		if (buf.readableBytes() < size)
			return;

		int version = buf.readInt();
		buf.readUnsignedByte();
		buf.readUnsignedByte();
		buf.readUnsignedByte();

		int displayMode = buf.readUnsignedByte(); // 0 = sd, 1 = hd small, 2 = hd resizable

		int width = buf.readUnsignedShort();
		int height = buf.readUnsignedShort();

		int antialiasing = buf.readUnsignedByte();

		byte[] uid = new byte[24];
		for (int i = 0; i < uid.length; i++)
			uid[i] = buf.readByte();

		String settings = ByteBufUtils.readString(buf);

		int affiliate = buf.readInt();
		int flags = buf.readInt();

		buf.readShort();

		int[] crc = new int[28];
		for (int i = 0; i < crc.length; i++)
			crc[i] = buf.readInt();

		int encryptedSize = buf.readUnsignedByte();
		ByteBuf secureBuffer = ByteBufUtils.rsa(buf.readBytes(encryptedSize), RsaKeySet.MODULUS, RsaKeySet.PRIVATE_KEY);

		int encryptedType = secureBuffer.readUnsignedByte();
		if (encryptedType != 10)
			throw new IOException("Invalid encrypted block type.");

		long clientSessionKey = secureBuffer.readLong();
		long serverSessionKey = secureBuffer.readLong();

		long encodedUsername = secureBuffer.readLong();
		String username = Base37Utils.decodeBase37(encodedUsername);
		String password = ByteBufUtils.readString(secureBuffer);

		if (((encodedUsername >> 16) & 31) != hash)
			throw new IOException("Username hash mismatch.");

		boolean reconnecting = type == 16;
		out.add(new LoginRequest(reconnecting, username, password, clientSessionKey, serverSessionKey, version, crc, displayMode));

		ctx.pipeline().remove(this);
	}
}
 
开发者ID:davidi2,项目名称:mopar,代码行数:70,代码来源:LoginDecoder.java


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