Thread: Help networking issue

Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1 Help networking issue 
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Hey guys,

    I am lost, i don't know shit about networking and now i have some big ass issue.
    I never hosted my server, always tested local host first time i am hosting from a different IP as localhost and i'm receiving this error:

    What do i need to do to fix?

    Code:
    Logging started at 2018-04-14 11:33:54
    File name: C:\Users\Administrator\Desktop\Server\.\err\1523730834725 - Administrator - [Sat Apr 14][11.33AM].txt
    System.getProperty("os.name"): "Windows Server 2012 R2"
    
    [2018-04-14 11:34:29] [nioEventLoopGroup-2-2] INFO com.venenatis.game.net.LoginManager - Added pending login req
    [2018-04-14 11:34:30] [pool-4-thread-1] INFO com.venenatis.game.net.LoginManager - Login request being handled for Test on the Login IO thread.
    [2018-04-14 11:34:30] [pool-4-thread-1] INFO com.venenatis.game.net.LoginManager - Test from 92.110.187.60
    [2018-04-14 11:34:30] [pool-4-thread-1] INFO com.venenatis.game.net.LoginManager - Login req for Test complete on the LOGIN thread in -265ms!
    [2018-04-14 11:34:32] java.lang.UnsupportedOperationException: direct buffer
    [2018-04-14 11:34:32] 	at io.netty.buffer.PooledUnsafeDirectByteBuf.array(PooledUnsafeDirectByteBuf.java:343)
    [2018-04-14 11:34:32] 	at io.netty.buffer.WrappedByteBuf.array(WrappedByteBuf.java:949)
    [2018-04-14 11:34:32] 	at com.venenatis.game.net.network.session.GameSession.processQueuedPackets(GameSession.java:43)
    [2018-04-14 11:34:32] 	at com.venenatis.game.world.World.handlePreUpdating(World.java:472)
    [2018-04-14 11:34:32] 	at com.venenatis.game.world.World.pulse(World.java:401)
    [2018-04-14 11:34:32] 	at com.venenatis.server.GameEngine.cycle(GameEngine.java:125)
    [2018-04-14 11:34:32] 	at com.venenatis.server.GameEngine.run(GameEngine.java:84)
    [2018-04-14 11:34:32] 	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    [2018-04-14 11:34:32] 	at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    [2018-04-14 11:34:32] 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    [2018-04-14 11:34:32] 	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    [2018-04-14 11:34:32] 	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    [2018-04-14 11:34:32] 	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    [2018-04-14 11:34:32] 	at java.lang.Thread.run(Unknown Source)
    [2018-04-14 11:34:34] [pool-4-thread-1] INFO com.venenatis.game.net.LoginManager - Profile saved for Test on the Login IO thread.
    [2018-04-14 11:34:34] [nioEventLoopGroup-2-1] ERROR io.netty.util.ResourceLeakDetector - LEAK: ByteBuf.release() was not called before it's garbage-collected. See http://netty.io/wiki/reference-counted-objects.html for more information.
    Recent access records: 1
    #1:
    	io.netty.buffer.AdvancedLeakAwareByteBuf.writeBytes(AdvancedLeakAwareByteBuf.java:600)
    	io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:849)
    	io.netty.buffer.WrappedByteBuf.readBytes(WrappedByteBuf.java:616)
    	io.netty.buffer.AdvancedLeakAwareByteBuf.readBytes(AdvancedLeakAwareByteBuf.java:469)
    	com.venenatis.game.net.network.codec.RS2Decoder.decode(RS2Decoder.java:53)
    	io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
    	io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
    	io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    	io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    	io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    	io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)
    	io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
    	io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
    	io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
    	io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
    	io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
    	io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    	io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
    	java.lang.Thread.run(Unknown Source)
    Created at:
    	io.netty.util.ResourceLeakDetector.track(ResourceLeakDetector.java:237)
    	io.netty.buffer.PooledByteBufAllocator.newDirectBuffer(PooledByteBufAllocator.java:331)
    	io.netty.buffer.AbstractByteBufAllocator.directBuffer(AbstractByteBufAllocator.java:181)
    	io.netty.buffer.AbstractByteBufAllocator.buffer(AbstractByteBufAllocator.java:117)
    	io.netty.buffer.AbstractByteBuf.readBytes(AbstractByteBuf.java:848)
    	io.netty.buffer.WrappedByteBuf.readBytes(WrappedByteBuf.java:616)
    	io.netty.buffer.AdvancedLeakAwareByteBuf.readBytes(AdvancedLeakAwareByteBuf.java:469)
    	com.venenatis.game.net.network.codec.RS2Decoder.decode(RS2Decoder.java:53)
    	io.netty.handler.codec.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:489)
    	io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:428)
    	io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:265)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    	io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:340)
    	io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1359)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:362)
    	io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:348)
    	io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:935)
    	io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:134)
    	io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:645)
    	io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:580)
    	io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:497)
    	io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:459)
    	io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:858)
    	io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:138)
    	java.lang.Thread.run(Unknown Source)
    [2018-04-14 11:34:34] [nioEventLoopGroup-2-1] INFO com.venenatis.game.net.LoginManager - Added pending login req
    Code:
    	public void processQueuedPackets() {
    		//long startTime = System.currentTimeMillis();
    		Packet p = null;
    		int processed = 0;
    		while ((p = queuedPackets.poll()) != null) {
    			//Only allow 20 packets sent otherwise someone floods the server.
    			if (processed > Constants.MAX_INCOMING_PACKETS_PER_CYCLE) {
    				break;
    			}
    			player.sendIncomingPacket().offset = 0;
    			player.sendIncomingPacket().buffer = p.getPayload().array();//ERROR HERE line 43
    			if (p.getOpcode() > 0) {
    				PacketHandler.processPacket(player, p.getOpcode(), p.getPayload().readableBytes());
    				processed++;
    			}
    		}
    		//long endTime = System.currentTimeMillis() - startTime; System.out.println("[processQueuedPackets] end time: "+endTime + " : players online: " + World.getWorld().getPlayers().size());
    	}
    Please help me

    Kind regards,

    Patrick
    Reply With Quote  
     

  2. #2  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    It's because your p.getPayload() method returns a ByteBuf that is not backed by an array. You can read more about it here: https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html .

    As for how to fix it, make a utility method (ByteBufUtils.java is a nice way to do this, you should have a class like this anyways) that gets an array from a ByteBuf IF it is backed by array, or if it is not backed by an array, convert it to a byte array using ByteBuf#getBytes.
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Andys1814 View Post
    It's because your p.getPayload() method returns a ByteBuf that is not backed by an array. You can read more about it here: https://netty.io/4.0/api/io/netty/buffer/ByteBuf.html .

    As for how to fix it, make a utility method (ByteBufUtils.java is a nice way to do this, you should have a class like this anyways) that gets an array from a ByteBuf IF it is backed by array, or if it is not backed by an array, convert it to a byte array using ByteBuf#getBytes.
    Found that no clue what so ever sorry, however i do have such class:

    Code:
    package com.venenatis.game.util;
    
    import java.io.ByteArrayOutputStream;
    import java.nio.ByteBuffer;
    
    /**
     * A static-utility class containing extension or helper methods for {@link
     * ByteBuffer}s.
     *
     * @author Ryley Kimmel <[email protected]>
     */
    public final class ByteBufUtils {
    
        /**
         * The terminator used within the client, equal to <tt>10</tt> and otherwise
         * know as the Jagex {@code String} terminator.
         */
        public static final char J_STRING_TERMINATOR = '\n';
    
        /**
         * The default {@code String} terminator, equal to <tt>0</tt> and otherwise
         * known as the 'null' {@code String} terminator.
         */
        public static final char DEFAULT_STRING_TERMINATOR = '\0';
    
        /**
         * Gets a 24-bit medium integer from the specified {@link ByteBuffer}, this
         * method does not mark the ByteBuffers current position.
         *
         * @param buffer The ByteBuffer to read from.
         * @return The read 24-bit medium integer.
         */
        public static int getMedium(ByteBuffer buffer) {
            return (buffer.getShort() & 0xFFFF) << 8 | buffer.get() & 0xFF;
        }
    
        /**
         * Gets a null-terminated String from the specified ByteBuffer.
         *
         * @param buffer The ByteBuffer to read from.
         * @return The null-terminated String.
         */
        public static String getString(ByteBuffer buffer) {
            return getString(buffer, DEFAULT_STRING_TERMINATOR);
        }
    
        /**
         * Gets a newline-terminated String from the specified ByteBuffer.
         *
         * @param buffer The ByteBuffer to read from.
         * @return The newline-terminated String.
         */
        public static String getJString(ByteBuffer buffer) {
            return getString(buffer, J_STRING_TERMINATOR);
        }
    
        /**
         * Reads {@code length} bytes from the specified {@link ByteBuffer}.
         *
         * @param buffer The ByteBuffer to read from.
         * @param length The amount of bytes to read.
         * @return The read bytes.
         */
        public static byte[] get(ByteBuffer buffer, int length) {
            byte[] data = new byte[length];
            buffer.get(data);
            return data;
        }
    
        /**
         * Gets a {@link String} from the specified {@link ByteBuffer}, the
         * ByteBuffer will continue to get until the specified {@code terminator} is
         * reached. <p> We use a {@link ByteArrayOutputStream} as it is self
         * expanding. We don't want to waste precious time determining a fixed
         * length for the {@code String}. </p>
         *
         * @param buffer     The ByteBuffer to read from.
         * @param terminator The terminator which denotes when to stop reading.
         * @return The read String.
         */
        public static String getString(ByteBuffer buffer, char terminator) {
            ByteArrayOutputStream os = new ByteArrayOutputStream();
            for (; ; ) {
                int read = buffer.get() & 0xFF;
                if (read == terminator) {
                    break;
                }
                os.write(read);
            }
            return new String(os.toByteArray());
        }
    
        /**
         * Reads a 'smart' (either a {@code byte} or {@code short} depending on the
         * value) from the specified buffer.
         *
         * @param buffer The buffer.
         * @return The 'smart'.
         */
        public static int getSmart(ByteBuffer buffer) {
            int peek = buffer.get(buffer.position()) & 0xFF;
            if (peek < 128) {
                return buffer.get() & 0xFF;
            }
            return (buffer.getShort() & 0xFFFF) - 32768;
        }
    
        /**
         * Puts a 'smart' (either a {@code byte} or {@code short}.
         *
         * @param buffer The buffer.
         * @param value  The value to write.
         */
        public static void putSmart(ByteBuffer buffer, int value) {
            if (value < 128) {
                buffer.put((byte) value);
            } else {
                value += 32768;
                buffer.put((byte) (value >> 8));
                buffer.put((byte) value);
            }
        }
    
        /**
         * Sole private constructor to discourage instantiation of this class.
         */
        private ByteBufUtils() {
        }
    
    }
    Last edited by _Patrick_; 04-15-2018 at 01:35 PM.
    Reply With Quote  
     

  4. #4  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    You're using a WrappedByteBuf and providing a ByteBuf that doesn't support #array(). Look for usages of WrappedByteBuf in your source, specifically during the login block, and make sure its backed by a ByteBuf with support to #array().
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    You're using a WrappedByteBuf and providing a ByteBuf that doesn't support #array(). Look for usages of WrappedByteBuf in your source, specifically during the login block, and make sure its backed by a ByteBuf with support to #array().
    None, are there. Mind helping over tv?
    Reply With Quote  
     

  6. #6  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Quote Originally Posted by _Patrick_ View Post
    None, are there. Mind helping over tv?
    Not really, but provide your encoder and decoder for constructing and deconstructing packets when received and sent on the server end.
    Reply With Quote  
     

  7. #7  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    Not really, but provide your encoder and decoder for constructing and deconstructing packets when received and sent on the server end.
    Code:
    package com.venenatis.game.net.network.login;
    
    import com.venenatis.game.net.network.NetworkConstants;
    import com.venenatis.game.net.network.rsa.ISAACRandomGen;
    import com.venenatis.game.net.packet.Packet;
    import com.venenatis.game.util.Utils;
    import io.netty.buffer.ByteBuf;
    import io.netty.buffer.Unpooled;
    import io.netty.channel.Channel;
    import io.netty.channel.ChannelFuture;
    import io.netty.channel.ChannelFutureListener;
    import io.netty.channel.ChannelHandlerContext;
    import io.netty.handler.codec.ByteToMessageDecoder;
    
    import java.math.BigInteger;
    import java.security.SecureRandom;
    import java.util.List;
    
    public class RS2LoginProtocol extends ByteToMessageDecoder {
    
    	private enum State {
    		HANDSHAKE, HEADER, LOGIN
    	}
    
    	private static final SecureRandom RANDOM = new SecureRandom();
    
    	private State state = State.HANDSHAKE;
    
    	private int packetLength;
    
    	private String readRS2String(ByteBuf in) {
    		StringBuilder bldr = new StringBuilder();
    		byte b;
    		while (in.isReadable() && ((b = in.readByte()) != 10)) {
    			bldr.append((char) b);
    		}
    		return bldr.toString();
    	}
    
    	public static void sendReturnCode(Channel channel, int code) {
    		ByteBuf buffer = channel.alloc().buffer(Byte.BYTES).writeByte(code);
    		ChannelFuture future = channel.writeAndFlush(new Packet(-1, buffer));
    		future.addListener(ChannelFutureListener.CLOSE);
    		buffer.release();
    	}
    
    	private static void finish(ByteBuf buf) {
    		if (buf.isReadable()) {
    			buf.readBytes(buf.readableBytes());
    		}
    	}
    
    	@Override
    	protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    		switch (state) {
    		case HANDSHAKE:
    			if (buf.readableBytes() < 1) {
    				return;
    			}
    			buf.readUnsignedByte();
    			ByteBuf buffer = ctx.alloc().buffer(Long.BYTES * 2 + Byte.BYTES);
    			buffer.writeLong(0).writeByte(0).writeLong(RANDOM.nextLong());
    			ctx.channel().writeAndFlush(new Packet(-1, buffer));
    			state = State.HEADER;
    			break;
    		case HEADER:
    			if (buf.readableBytes() < 2) {
    				finish(buf);
    				ctx.channel().close();
    				return;
    			}
    
    			int loginType = buf.readUnsignedByte();
    			if ((loginType != 16) && (loginType != 18)) {
    				System.out.println("Invalid login type: " + loginType);
    				finish(buf);
    				sendReturnCode(ctx.channel(), 15);
    				return;
    			}
    
    			packetLength = buf.readUnsignedByte();
    
    			if (packetLength <= 0) {
    				finish(buf);
    				sendReturnCode(ctx.channel(), 15);
    				return;
    			}
    			state = State.LOGIN;
    			break;
    		case LOGIN:
    
    			int encryptedBlockLength = packetLength - 40;
    			if (buf.readableBytes() < packetLength) {
    				finish(buf);
    				sendReturnCode(ctx.channel(), 15);
    				return;
    			}
    			buf.readByte();
    
    			buf.readShort();
    
    			buf.readByte();
    
    			for (int i = 0; i < 9; i++) {
    				buf.readInt();
    			}
    
    			encryptedBlockLength--;
    			if (encryptedBlockLength != (buf.readUnsignedByte())) {
    				System.out.println("Encrypted size mismatch.");
    				finish(buf);
    				sendReturnCode(ctx.channel(), 15);
    				return;
    			}
    			byte[] encryptedBytes = new byte[encryptedBlockLength];
    			buf.readBytes(encryptedBytes);
    			ByteBuf encryptedBuffer = Unpooled.wrappedBuffer(new BigInteger(encryptedBytes).modPow(NetworkConstants.RSA_EXPONENT, NetworkConstants.RSA_MODULUS).toByteArray());
    
    			int rsaOpcode = encryptedBuffer.readUnsignedByte();
    			if (rsaOpcode != 10) {
    				finish(buf);
    				sendReturnCode(ctx.channel(), 24);
    				return;
    			}
    
    			long clientHalf = encryptedBuffer.readLong();
    			long serverHalf = encryptedBuffer.readLong();
    			int[] isaacSeed = { (int) (clientHalf >> 32), (int) clientHalf, (int) (serverHalf >> 32), (int) serverHalf };
    			ISAACRandomGen inCipher = new ISAACRandomGen(isaacSeed);
    			for (int i = 0; i < isaacSeed.length; i++) {
    				isaacSeed[i] += 50;
    			}
    			ISAACRandomGen outCipher = new ISAACRandomGen(isaacSeed);
    			int uid = encryptedBuffer.readInt();
    			int clientVersion = encryptedBuffer.readInt();
    			String name = Utils.formatName(readRS2String(encryptedBuffer));
    			String pass = readRS2String(encryptedBuffer);
    			String identity = readRS2String(encryptedBuffer);
    			String macAddress = readRS2String(encryptedBuffer);
    			//System.out.println("yo "+name+" "+pass+" "+identity+" "+macAddress+" "+uid);
    			ctx.channel().pipeline().replace("encoder", "encoder", new LoginEncoder());
    			out.add(new LoginCredential(name, pass, identity, macAddress, inCipher, outCipher, uid, clientVersion));
    		}
    	}
    }
    Code:
    package com.venenatis.game.net.network.login;
    
    import io.netty.buffer.ByteBuf;
    import io.netty.buffer.Unpooled;
    import io.netty.channel.ChannelHandlerContext;
    import io.netty.handler.codec.MessageToMessageEncoder;
    
    import java.util.List;
    
    /**
     * A {@link MessageToMessageEncoder} which encodes the values received from the
     * login protocol.
     *
     * @author Mobster
     */
    public final class LoginEncoder extends MessageToMessageEncoder<LoginResponse> {
    
    	@Override
    	protected void encode(ChannelHandlerContext ctx, LoginResponse response, List<Object> out) throws Exception {
    		ByteBuf buffer = Unpooled.buffer(3);
    		buffer.writeByte(response.getResponse());
    		if (response.getResponse() == 2) {
    			buffer.writeByte(response.getRights());
    			buffer.writeByte(response.getFlagStatus());
    		}
    
    		out.add(buffer);
    	}
    
    }
    Reply With Quote  
     

  8. #8  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    For packets, not the login block.

    > com.venenatis.game.net.network.codec.RS2Decoder.de code(RS2Decoder.java:53)
    Reply With Quote  
     

  9. #9  
    Banned

    Join Date
    Oct 2012
    Posts
    4,710
    Thanks given
    1,679
    Thanks received
    1,105
    Rep Power
    0
    Quote Originally Posted by Jason View Post
    For packets, not the login block.

    > com.venenatis.game.net.network.codec.RS2Decoder.de code(RS2Decoder.java:53)
    Code:
    package com.venenatis.game.net.network.codec;
    
    import io.netty.channel.ChannelHandlerContext;
    import io.netty.handler.codec.MessageToMessageEncoder;
    
    import java.util.List;
    
    import com.venenatis.game.net.packet.Packet;
    
    public final class RS2Encoder extends MessageToMessageEncoder<Packet> {
    
    	@Override
    	protected void encode(ChannelHandlerContext ctx, Packet packet, List<Object> out) throws Exception {
    		try {
    			out.add(packet.getPayload());
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    }
    Code:
    package com.venenatis.game.net.network.codec;
    
    import io.netty.buffer.ByteBuf;
    import io.netty.channel.ChannelHandlerContext;
    import io.netty.handler.codec.ByteToMessageDecoder;
    
    import java.util.List;
    
    import com.venenatis.game.net.network.rsa.ISAACRandomGen;
    import com.venenatis.game.net.packet.Packet;
    
    public class RS2Decoder extends ByteToMessageDecoder {
    
    	private final ISAACRandomGen cipher;
    
    	private int opcode = -1;
    	private int size = -1;
    
    	public RS2Decoder(ISAACRandomGen cipher) {
    		this.cipher = cipher;
    	}
    
    	@Override
    	protected void decode(ChannelHandlerContext ctx, ByteBuf buf, List<Object> out) throws Exception {
    
    		try {
    			if (opcode == -1) {
    				if (buf.readableBytes() < 1) {
    					return;
    				}
    
    				opcode = buf.readUnsignedByte();
    				opcode = (opcode - cipher.getNextKey()) & 0xFF;
    				size = Packet.PACKET_SIZES[opcode];
    			}
    
    			if (size == -1) {
    				if (buf.readableBytes() < 1) {
    					return;
    				}
    
    				size = buf.readUnsignedByte();
    			}
    
    			if (buf.readableBytes() < size) {
    				return;
    			}
    
    			try {
    				/*
    				 * Produce and write the packet object.
    				 */
    				out.add(new Packet(opcode, buf.readBytes(size)));
    			} finally {
    				opcode = size = -1;
    			}
    		} catch (Exception e) {
    			e.printStackTrace();
    		}
    	}
    
    }
    Reply With Quote  
     

  10. #10  
    Registered Member
    Andys1814's Avatar
    Join Date
    Feb 2013
    Posts
    974
    Thanks given
    688
    Thanks received
    455
    Rep Power
    727
    i told u the fix, i didn't know how specific i had to be but w/e:

    Code:
    public static byte[] toByteArray(ByteBuf buf) {
            if (buf.hasArray()) {
                    return buf.array();
            }
          
            byte[] bytes = new byte[buf.readableBytes()];
            buf.getBytes(buf.readerIndex(), bytes);
    
            return bytes;
    
    }
    Reply With Quote  
     

  11. Thankful user:


Page 1 of 2 12 LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. Need help, Webclient issue
    By addicted in forum Help
    Replies: 5
    Last Post: 04-14-2011, 02:07 AM
  2. Replies: 4
    Last Post: 10-15-2010, 04:45 AM
  3. Replies: 0
    Last Post: 06-02-2010, 03:08 AM
  4. Quick Help - Xp Issues
    By MadZ in forum Help
    Replies: 0
    Last Post: 05-31-2010, 10:12 PM
  5. ::help Menu Issues
    By Jpa7777777 in forum Help
    Replies: 1
    Last Post: 06-24-2009, 09:07 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •