List of usage examples for io.netty.buffer Unpooled buffer
public static ByteBuf buffer()
From source file:com.vethrfolnir.game.network.mu.crypt.MuDecoder.java
License:Open Source License
public static void main(String[] args) { //byte[] data = PacketUtils.hex2Bytes("C1 04 F3 0D d3"); //byte[] data = PacketUtils.hex2Bytes("C1 0F F3 7B 85 58 A8 B9 E9 41 BF 09 40 1D 74"); byte[] data = PacketUtils.hex2Bytes( "C3 5A 9E 4D 18 56 28 FB 20 E5 2D A7 92 5A 01 33 CB 50 BA F0 10 69 76 43 16 D1 65 36 64 13 F1 45 CC 1A 2F B1 B7 4E 24 49 1F F2 2F 54 A7 92 F8 04 7E 8A A7 A7 73 EF 00 C9 FC E2 CF 35 E4 58 21 A0 5C 89 16 23 B2 8C 5C 4C 62 23 B2 8B 90 27 12 61 07 5D 00 4D C3 F3 5A 31 99 A7"); ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); ByteBuf out = null;/* ww w .j a v a2 s . c o m*/ for (int i = 0; i < 1; i++) { buff.writeBytes(data); long t1 = System.currentTimeMillis(); //DecodeXor32(buff); out = DecodePacket(buff); long t2 = System.currentTimeMillis(); System.out.println("Process time: " + (t2 - t1) + " milis"); } System.out.println(PrintData.printData(out.nioBuffer())); }
From source file:com.vethrfolnir.game.network.mu.crypt.MuEncoder.java
License:Open Source License
public static void main(String[] args) { Corax.Install(new CoraxBuilder() { @Override/* ww w .j av a2 s .com*/ protected void build(Corax corax) { CorvusConfig.WorkingDirectory = new File("./dist/GameServer"); Corax.config().loadDirectory("/config"); bind(AssetManager.class).as(Scope.Singleton); ; } }); MuKeyFactory.parse(); System.out.println(""); //byte[] data = PacketUtils.hex2Bytes("C3 44 F3 03 42 E6 33 00 00 00 00 00 00 00 FA 00 00 00 00 00 00 01 25 84 0A 00 2D 00 32 00 12 00 28 00 56 00 56 00 59 00 59 00 C8 00 C8 00 10 00 20 00 12 00 B0 B4 1D 00 03 00 00 00 04 00 00 00 00 00 04 00"); byte[] data = PacketUtils.hex2Bytes( "C4 00 2D 01 F3 10 03 00 00 00 12 00 00 10 00 FF FF FF FF FF 0C 14 08 1E 00 00 D0 00 FF FF FF FF FF 0D 14 10 1E 00 00 D0 00 FF FF FF FF"); ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); buff.writeBytes(data); ByteBuf out = EncodePacket(buff, 0x02); byte[] arr = new byte[out.readableBytes()]; out.readBytes(arr); //System.out.println(PrintData.printData(out.nioBuffer())); //System.out.println("C3-65-22-EF-31-62-4B-D5-32-2F-B1-AA-9F-45-1B-08-45-D2-96-92-B1-51-37-02-45-1B-1F-83-13-D1-F3-9C-E6-67-52-9C-F7-0F-7C-CD-9B-E1-EC-B4-E8-DD-3D-33-0D-44-C2-73-52-48-4E-CD-F8-98-77-44-8B-99-FA-64-71-A6-FD-C8-35-92-35-B9-95-3D-A2-3C-81-C5-F0-0F-4E-1D-F0-81-34-72-2B-E8-C9-FC-36-05-31-36-80-D0-80-BB-0C-C2-FC"); System.out.println("C3-0D-FE-53-65-66-18-AB-51-01-C1-4D-77"); System.out.println(PacketUtils.byteArrayToHex(arr).toUpperCase()); }
From source file:com.vethrfolnir.game.network.mu.crypt.MuKeyFactory.java
License:Open Source License
private static void readFile(String path, long[] out_dat) { AssetManager assetManager = Corax.fetch(AssetManager.class); ByteBuf buff = Unpooled.buffer().order(ByteOrder.LITTLE_ENDIAN); try (InputStream is = assetManager.loadAsset(FileKey.class, path)) { buff.writeBytes(is, is.available()); } catch (IOException e) { e.printStackTrace();//from w w w . j a v a2 s . co m } buff.readerIndex(6); int pointer = 0; for (int i = 0; i < 3; i++) { long[] buf = new long[4]; for (int j = 0; j < 4; j++) { buf[j] = buff.readUnsignedInt(); } out_dat[pointer++] = buf[0] ^ (xor_tab_datfile[0]); out_dat[pointer++] = buf[1] ^ (xor_tab_datfile[1] & 0xFFFFFFFFL); out_dat[pointer++] = buf[2] ^ (xor_tab_datfile[2] & 0xFFFFFFFFL); out_dat[pointer++] = buf[3] ^ (xor_tab_datfile[3]); } }
From source file:com.whirvis.jraknet.Packet.java
License:Open Source License
/** * Creates a packet using the specified {@link ByteBuf} * //from ww w . j a v a 2s .c o m * @param buffer * the {@link ByteBuf} to read from and write to, a * <code>null</code> value will have a new buffer be used * instead. * @throws IllegalArgumentException * if the <code>buffer</code> is an {@link EmptyByteBuf}. */ public Packet(ByteBuf buffer) throws IllegalArgumentException { if (buffer instanceof EmptyByteBuf) { throw new IllegalArgumentException("No content"); } this.buffer = buffer == null ? Unpooled.buffer() : buffer; this.input = new PacketDataInputStream(this); this.output = new PacketDataOutputStream(this); }
From source file:com.whirvis.jraknet.Packet.java
License:Open Source License
/** * Updates the buffer./* ww w. j a v a 2 s. c om*/ * * @param buffer * the buffer to read from and write to, a <code>null</code> * value will have a new buffer be used instead. * @return the packet. */ public final Packet setBuffer(ByteBuf buffer) { this.buffer = buffer == null ? Unpooled.buffer() : buffer; return this; }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameEncoderTest.java
License:Open Source License
@Test public void testTestEncode() throws Exception { VantageSerialFrameEncoder encoder = new VantageSerialFrameEncoder(); com.whizzosoftware.hobson.davisvantage.api.command.Test test = new com.whizzosoftware.hobson.davisvantage.api.command.Test(); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, test, buf);/* w ww . j a v a 2 s .c om*/ assertEquals("TEST\n", buf.toString(Charset.forName("UTF8"))); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameEncoderTest.java
License:Open Source License
@Test public void testVersion() throws Exception { VantageSerialFrameEncoder encoder = new VantageSerialFrameEncoder(); VersionRequest ver = new VersionRequest(); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, ver, buf);//from w ww . j a va 2s .c o m assertEquals("VER\n", buf.toString(Charset.forName("UTF8"))); }
From source file:com.whizzosoftware.hobson.davisvantage.api.codec.VantageSerialFrameEncoderTest.java
License:Open Source License
@Test public void testLoopRequest() throws Exception { VantageSerialFrameEncoder encoder = new VantageSerialFrameEncoder(); com.whizzosoftware.hobson.davisvantage.api.command.LoopRequest ver = new com.whizzosoftware.hobson.davisvantage.api.command.LoopRequest( 5);// w w w . j a v a 2 s .c om ByteBuf buf = Unpooled.buffer(); encoder.encode(null, ver, buf); assertEquals("LOOP 5\n", buf.toString(Charset.forName("UTF8"))); }
From source file:com.whizzosoftware.hobson.radiora.api.codec.RadioRaFrameEncoderTest.java
License:Open Source License
@Test public void testSetDimmerLevelEncode() throws Exception { RadioRaFrameEncoder encoder = new RadioRaFrameEncoder(); // test with 3 digit level SetDimmerLevel sdl = new SetDimmerLevel(1, 100); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, sdl, buf);//www.j av a2s. com assertEquals("SDL,1,100\r", buf.toString(Charset.forName("UTF8"))); // test with 1 digit level sdl = new SetDimmerLevel(1, 1); buf = Unpooled.buffer(); encoder.encode(null, sdl, buf); assertEquals("SDL,1,1\r", buf.toString(Charset.forName("UTF8"))); // test with fade time sdl = new SetDimmerLevel(1, 1, 50); buf = Unpooled.buffer(); encoder.encode(null, sdl, buf); assertEquals("SDL,1,1,50\r", buf.toString(Charset.forName("UTF8"))); }
From source file:com.whizzosoftware.hobson.radiora.api.codec.RadioRaFrameEncoderTest.java
License:Open Source License
@Test public void testSetSwitchLevelEncode() throws Exception { RadioRaFrameEncoder encoder = new RadioRaFrameEncoder(); // test with single digit zone number SetSwitchLevel ssl = new SetSwitchLevel(1, true); ByteBuf buf = Unpooled.buffer(); encoder.encode(null, ssl, buf);/* www . j av a2s.c o m*/ assertEquals("SSL,1,ON\r", buf.toString(Charset.forName("UTF8"))); // test with double digit zone number ssl = new SetSwitchLevel(10, true); buf = Unpooled.buffer(); encoder.encode(null, ssl, buf); assertEquals("SSL,10,ON\r", buf.toString(Charset.forName("UTF8"))); // test with delay time ssl = new SetSwitchLevel(10, true, 50); buf = Unpooled.buffer(); encoder.encode(null, ssl, buf); assertEquals("SSL,10,ON,50\r", buf.toString(Charset.forName("UTF8"))); }