List of usage examples for io.netty.buffer ByteBuf readUnsignedByte
public abstract short readUnsignedByte();
From source file:com.vethrfolnir.game.network.mu.MuCyperDecoder.java
License:Open Source License
@Override protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception { if (!in.isReadable()) { MuClient client = ctx.channel().attr(MuClient.ClientKey).get(); _log.warn("Client[" + client + "] sent an empty packet!"); return; //XXX: is it critical? }/*from ww w .j a v a 2s . c o m*/ if (in.readableBytes() < 3) { return; // come back later } in.markReaderIndex(); int opcode = in.readUnsignedByte(); int lengthAt = 0; switch (opcode) { case 0xc1: case 0xc3: lengthAt = 1; break; case 0xc2: case 0xc4: lengthAt = 2; break; } //in.markReaderIndex(); int rez = lengthAt > 1 ? in.readShort() : in.readUnsignedByte(); in.resetReaderIndex(); //System.out.println("1 Size[point="+(lengthAt > 1 ? "Short" : "Unsigned byte")+"]: "+rez+" opcode "+Integer.toHexString(opcode & 0xFF)); if (in.readableBytes() < rez) { in.resetReaderIndex(); return; } int header = in.getUnsignedByte(0); if (header == 0xC1 || header == 0xC2) { ByteBuf buff = ctx.alloc().heapBuffer(rez); in.readBytes(buff); out.add(DecodeXor32(buff)); } else { out.add(DecodePacket(in)); } }
From source file:com.vethrfolnir.game.network.mu.packets.MuReadPacket.java
License:Open Source License
protected int readD(ByteBuf buff, ByteOrder order) { switch (order.toString()) { case "BIG_ENDIAN": { int a = buff.readUnsignedByte() << 8; int b = buff.readUnsignedByte() << 16; int c = buff.readUnsignedByte() << 32; int d = buff.readUnsignedByte() & 0xFF; return (a | b | c | d); }//from www . j a v a 2 s. c o m case "LITTLE_ENDIAN": { int a = buff.readUnsignedByte() & 0xFF; int b = buff.readUnsignedByte() << 32; int c = buff.readUnsignedByte() << 16; int d = buff.readUnsignedByte() << 8; return (a | b | c | d); } } throw new RuntimeException("Order: " + order + " is not mapped!"); }
From source file:com.vethrfolnir.game.network.mu.packets.MuReadPacket.java
License:Open Source License
protected int readSh(ByteBuf buff, ByteOrder order) { switch (order.toString()) { case "BIG_ENDIAN": { int a = buff.readUnsignedByte() << 8; int b = buff.readUnsignedByte() & 0xFF; return (a | b); }/*from w ww .j ava2 s .co m*/ case "LITTLE_ENDIAN": { int a = buff.readUnsignedByte() & 0xFF; int b = buff.readUnsignedByte() << 8; return (a | b); } } throw new RuntimeException("Order: " + order + " is not mapped!"); }
From source file:com.vethrfolnir.login.network.game.GameChannelHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buff = (ByteBuf) msg; int opcode = buff.readUnsignedByte(); switch (opcode) { case 0x0A: // first registration ServerRegistration.read(null, buff, nameService, ctx); break;/*from w ww . j av a 2 s. co m*/ case 0x0B: { nameService.getServer(ctx.channel()).setOnlinePlayers(buff.readInt()); ; } default: log.warn("Unknown packet[opcode = 0x" + PrintData.fillHex(opcode, 2) + "]"); break; } buff.release(); }
From source file:com.vethrfolnir.login.network.mu.ClientChannelHandler.java
License:Open Source License
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { ByteBuf buff = (ByteBuf) msg; switch (buff.getUnsignedByte(0)) { case 0xC1:/* www . ja v a 2s. c om*/ case 0xC2: case 0xC3: case 0xC4: break; default: ctx.close(); buff.release(); //TODO: maybe add a flood protector? log.warn("Client[" + ctx.channel() + "] is not a mu online client! Disconnecting!"); return; } // we are not interested in the header and size; buff.readerIndex(2); int opcode = buff.readUnsignedShort(); switch (opcode) { case 0xf4_03: { // Request Server information int serverId = buff.readUnsignedByte(); ByteBuf buf = ctx.alloc().heapBuffer().order(ByteOrder.LITTLE_ENDIAN); WritePacket packet = SendServerInfo.StaticPacket; packet.write(null, buf, nameService, serverId); packet.markLength(buf); ; ctx.writeAndFlush(buf); break; } case 0xf4_06: { // Request Server list ByteBuf buf = ctx.alloc().heapBuffer().order(ByteOrder.LITTLE_ENDIAN); WritePacket packet = SendServerLists.StaticPacket; packet.write(null, buf, nameService); packet.markLength(buf); ctx.writeAndFlush(buf); break; } default: log.warn("Unkown packet[OPCODE = " + Integer.toHexString(opcode) + "] Dump: " + PrintData.printData(buff.nioBuffer(0, buff.writerIndex()))); ctx.close(); break; } buff.release(); }
From source file:com.vethrfolnir.network.ReadPacket.java
License:Open Source License
protected short readC(ByteBuf buff) { return buff.readUnsignedByte(); }
From source file:cubicchunks.network.PacketCubeBlockChange.java
License:MIT License
@SuppressWarnings("deprecation") // Forge thinks we are trying to register a block or something :P @Override// w ww. ja va2 s .c om public void fromBytes(ByteBuf in) { this.cubePos = new CubePos(in.readInt(), in.readInt(), in.readInt()); short numBlocks = in.readShort(); localAddresses = new short[numBlocks]; blockStates = new IBlockState[numBlocks]; for (int i = 0; i < numBlocks; i++) { localAddresses[i] = in.readShort(); blockStates[i] = Block.BLOCK_STATE_IDS.getByValue(readVarInt(in, 4)); } int numHmapChanges = in.readUnsignedByte(); heightValues = new int[numHmapChanges]; for (int i = 0; i < numHmapChanges; i++) { heightValues[i] = in.readInt(); } }
From source file:de.gandev.modjn.entity.func.ModbusError.java
License:Apache License
@Override public void decode(ByteBuf data) { exceptionCode = data.readUnsignedByte(); setExceptionMessage(exceptionCode); }
From source file:de.gandev.modjn.entity.func.request.WriteMultipleCoilsRequest.java
License:Apache License
@Override public void decode(ByteBuf data) { super.decode(data); byteCount = data.readUnsignedByte(); byte[] coils = new byte[byteCount]; data.readBytes(coils);/* w w w . ja v a2 s. c o m*/ outputsValue = BitSet.valueOf(coils); }
From source file:de.gandev.modjn.entity.func.request.WriteMultipleRegistersRequest.java
License:Apache License
@Override public void decode(ByteBuf data) { super.decode(data); byteCount = data.readUnsignedByte(); registers = new int[byteCount / 2]; for (int i = 0; i < registers.length; i++) { registers[i] = data.readUnsignedShort(); }/*from w ww.j ava2 s. c o m*/ }