Thread: Custom Framework Question

Results 1 to 9 of 9
  1. #1 Custom Framework Question 
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    I'm trying to make my own framework, but I always get to the point of trying to log in, the problem is that it never gets passed the black screen....I'm pretty sure it has to do with map region packet and player updating right? Well I didn't know what was wrong with them so I just used hyperion's and still no luck:

    Spoiler for Update method:
    Code:
    public void update() {
    		/*
    		 * If the map region changed send the new one.
    		 * We do this immediately as the client can begin loading it before the
    		 * actual packet is received.
    		 */
    		if(player.isChangingRegion()) {
    			player.getPacketSender().sendMapRegion();
    		}
    		
    		/*
    		 * The update block packet holds update blocks and is send after the
    		 * main packet. 
    		 */
    		PacketBuilder updateBlock = new PacketBuilder();
    		
    		/*
    		 * The main packet is written in bits instead of bytes and holds
    		 * information about the local list, players to add and remove,
    		 * movement and which updates are required.
    		 */
    		PacketBuilder packet = new PacketBuilder(81, Packet.Type.VARIABLE_SHORT);
    		packet.startBitAccess();
    		
    		/*
    		 * Updates this player.
    		 */
    		updateThisPlayerMovement(packet);
    		updatePlayer(updateBlock, player, false, true);
    		
    		player.getLocalPlayers().add(player);
    		/*
    		 * Write the current size of the player list.
    		 */
    		packet.putBits(8, player.getLocalPlayers().size());
    		
    		/*
    		 * Iterate through the local player list.
    		 */
    		for(Iterator<Player> it$ = player.getLocalPlayers().iterator(); it$.hasNext();) {
    			/*
    			 * Get the next player.
    			 */
    			Player otherPlayer = it$.next();
    			/*
    			 * If the player should still be in our list.
    			 */
    			if(World.getPlayers().contains(otherPlayer) && !otherPlayer.isTeleporting() && otherPlayer.getPosition().isWithinDistance(player.getPosition())) {
    				/*
    				 * Update the movement.
    				 */
    				updatePlayerMovement(packet, otherPlayer);
    				
    				/*
    				 * Check if an update is required, and if so, send the update.
    				 */
    				if(otherPlayer.getUpdateFlag().isUpdateRequired()) {
    					updatePlayer(updateBlock, otherPlayer, false, false);
    				}
    			} else {
    				/*
    				 * Otherwise, remove the player from the list.
    				 */
    				it$.remove();
    				
    				/*
    				 * Tell the client to remove the player from the list.
    				 */
    				packet.putBits(1, 1);
    				packet.putBits(2, 3);
    			}
    		}
    
    		/*
    		 * Loop through every player.
    		 */
    		for(Player otherPlayer : Region.getLocalPlayers(player)) {
    			/*
    			 * Check if there is room left in the local list.
    			 */
    			if(player.getLocalPlayers().size() >= 255) {
    				/*
    				 * There is no more room left in the local list. We cannot add
    				 * more players, so we just ignore the extra ones. They will be
    				 * added as other players get removed.
    				 */
    				break;
    			}
    			
    			/*
    			 * If they should not be added ignore them.
    			 */
    			if(otherPlayer == player || player.getLocalPlayers().contains(otherPlayer)) {
    				continue;
    			}
    			
    			/*
    			 * Add the player to the local list if it is within distance.
    			 */
    			player.getLocalPlayers().add(otherPlayer);
    			
    			/*
    			 * Add the player in the packet.
    			 */
    			addNewPlayer(packet, otherPlayer);
    			
    			/*
    			 * Update the player, forcing the appearance flag.
    			 */
    			updatePlayer(updateBlock, otherPlayer, true, false);
    		}
    		
    		/*
    		 * Check if the update block is not empty.
    		 */
    		if(!updateBlock.isEmpty()) {
    			/*
    			 * Write a magic id indicating an update block follows.
    			 */
    			packet.putBits(11, 2047);
    			packet.finishBitAccess();
    			
    			/*
    			 * Add the update block at the end of this packet.
    			 */
    			packet.put(updateBlock.toPacket().getPayload());
    		} else {
    			/*
    			 * Terminate the packet normally.
    			 */
    			packet.finishBitAccess();
    		}
    		
    		/*
    		 * Write the packet.
    		 */
    		player.getChannel().write(packet.toPacket());
    	}


    Spoiler for sendMapRegion method:
    Code:
    public PacketSender sendMapRegion() {
    		player.getChannel().write(new PacketBuilder(73).putShortA(player.getPosition().getRegionX() + 6).putShort(player.getPosition().getRegionY() + 6).toPacket());
    		player.setLastKnownRegion(player.getPosition());
    		return this;
    	}


    And I am calling it upon login:

    Spoiler for init:
    Code:
    /**
    	 * Sends all the login packets.
    	 * @return The packet sender instance, for chaining.
    	 */
    	public PacketSender sendLogin() {
    		World.register(player);
    		sendMapRegion();
    		player.getChannel().write(new PacketBuilder(249).putByteA(1).putLEShortA(player.getIndex()).toPacket());
    		for (int i = 0; i < Skills.MAX_SKILLS; i++) {
    			sendSkill(i);
    		}
    		sendSidebarInterface(0, 2423); // attack tab
    		sendSidebarInterface(1, 3917); // skills tab
    		sendSidebarInterface(2, 638); // quest tab
    		sendSidebarInterface(3, 3213); // backpack tab
    		sendSidebarInterface(4, 1644); // items wearing tab
    		sendSidebarInterface(5, 5608); // pray tab
    		sendSidebarInterface(6, 1151); // magic tab
    		sendSidebarInterface(7, -1); // clan chat
    		sendSidebarInterface(8, 5065); // friend
    		sendSidebarInterface(9, 5715); // ignore
    		sendSidebarInterface(10, 2449); // logout tab
    		sendSidebarInterface(11, 904); // wrench tab
    		sendSidebarInterface(12, 147); // run tab
    		sendSidebarInterface(13, -1); // harp tab
    		
    		sendInteractionOption("Attack", 2, false);
    		sendInteractionOption("Follow", 3, false);
    		sendInteractionOption("Trade With", 4, false);
    		sendItemContainer(player.getInventory(), Inventory.INTERFACE);
    		sendItemContainer(player.getEquipment(), Equipment.INTERFACE);
    
    		sendMessage("Welcome to RuneScape.");
    		return this;
    	}
    Code:
    if (loginOpcode == 2) {
    			PacketBuilder packetBuilder = new PacketBuilder();
    			packetBuilder.put((byte) loginOpcode);
    			packetBuilder.put((byte) 0);
    			packetBuilder.put((byte) 0);
    			player.getChannel().write(packetBuilder.toPacket());
    			player.getPacketSender().sendLogin();
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Oct 2012
    Posts
    83
    Thanks given
    3
    Thanks received
    9
    Rep Power
    11
    To see something on the screen make sure you send the map region followed by the first player updating packet.

    my code.
    Code:
    /**
    	 * Sends the map region to the client.
    	 */
    	public void sendMapRegion() {
    		outBuffer.createFrame(73);
    		outBuffer.writeWordA(3500 >> 3);
    		outBuffer.putShort(3500 >> 3);
    		flushOutBuffer();
    	}
    		/**
    	 * Updates the client, sends appearance, other players around, position,
    	 * etc.
    	 */
    	private void updatePlayer() {
    
    		// players initialization
    		outBuffer.createFrame(81);
    		// placeholder for packet size.
    		outBuffer.putShort(0);
    
    		int ofs = outBuffer.position;
    		outBuffer.initializeBitAccess();
    
    		// update this player
    
    		// 1 for updating player, 0 for not.
    		outBuffer.writeBits(1, 1);
    
    		// update type. 0 - 3.
    		outBuffer.writeBits(2, 3);
    
    		// height.
    		outBuffer.writeBits(2, 0);
    		
    		// discard walking queue. (after teleporting etc.)
    		outBuffer.writeBits(1, 0); 
    		
    		
    		// ??
    		outBuffer.writeBits(1, 1); 
    		
    		// 'local' y.
    		outBuffer.writeBits(7, 0x29); 
    		
    		// 'local' x.
    		outBuffer.writeBits(7, 50); 
    
    		// amount of other players to update.
    		outBuffer.writeBits(8, 0); 
    
    		// ??
    		outBuffer.writeBits(11, 2047); 
    		outBuffer.finishBitAccess();
    
    		outBuffer.put(0); 
    		outBuffer.writeFrameSizeWord(outBuffer.position - ofs);
    
    		// write after each packet.
    		flushOutBuffer();
    	}
    Reply With Quote  
     

  3. #3  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Dinkleberg View Post
    To see something on the screen make sure you send the map region followed by the first player updating packet.

    my code.
    Code:
    /**
    	 * Sends the map region to the client.
    	 */
    	public void sendMapRegion() {
    		outBuffer.createFrame(73);
    		outBuffer.writeWordA(3500 >> 3);
    		outBuffer.putShort(3500 >> 3);
    		flushOutBuffer();
    	}
    		/**
    	 * Updates the client, sends appearance, other players around, position,
    	 * etc.
    	 */
    	private void updatePlayer() {
    
    		// players initialization
    		outBuffer.createFrame(81);
    		// placeholder for packet size.
    		outBuffer.putShort(0);
    
    		int ofs = outBuffer.position;
    		outBuffer.initializeBitAccess();
    
    		// update this player
    
    		// 1 for updating player, 0 for not.
    		outBuffer.writeBits(1, 1);
    
    		// update type. 0 - 3.
    		outBuffer.writeBits(2, 3);
    
    		// height.
    		outBuffer.writeBits(2, 0);
    		
    		// discard walking queue. (after teleporting etc.)
    		outBuffer.writeBits(1, 0); 
    		
    		
    		// ??
    		outBuffer.writeBits(1, 1); 
    		
    		// 'local' y.
    		outBuffer.writeBits(7, 0x29); 
    		
    		// 'local' x.
    		outBuffer.writeBits(7, 50); 
    
    		// amount of other players to update.
    		outBuffer.writeBits(8, 0); 
    
    		// ??
    		outBuffer.writeBits(11, 2047); 
    		outBuffer.finishBitAccess();
    
    		outBuffer.put(0); 
    		outBuffer.writeFrameSizeWord(outBuffer.position - ofs);
    
    		// write after each packet.
    		flushOutBuffer();
    	}
    Like I said...I know it has to do with both of those and is why I included the methods I'm using to see if there's anything wrong with them
    Reply With Quote  
     

  4. #4  
    Registered Member
    Join Date
    Oct 2012
    Posts
    83
    Thanks given
    3
    Thanks received
    9
    Rep Power
    11
    I suggest you print out the read data client sided, and see if the data is even sent.
    Reply With Quote  
     

  5. #5  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Dinkleberg View Post
    I suggest you print out the read data client sided, and see if the data is even sent.
    It is...I'm getting t1/t2 errors which has to do with packet errors...Either way what data are you even talking about?..
    Reply With Quote  
     

  6. #6  
    Community Veteran

    Dexter Morgan's Avatar
    Join Date
    Nov 2008
    Age
    28
    Posts
    4,419
    Thanks given
    1,184
    Thanks received
    757
    Rep Power
    3098
    Mate you're doing it wrong.

    You have to do it in the correct order for the login procedure. What you are doing is you are sending a packet to a player that doesn't
    exist, and then in that method you register him..

    You clearly don't know what you are doing here and should go study other frameworks as this is pretty important and complicated.
    Reply With Quote  
     

  7. #7  
    Registered Member
    Join Date
    Oct 2012
    Posts
    83
    Thanks given
    3
    Thanks received
    9
    Rep Power
    11
    It's also a good idea to make singleplayer work, not multiplayer at once.

    Also: as you could see in my code snippet, it's only singleplayer. And no walking/appearance updating/etc, this way you can debug smaller pieces than when you program much at a time.
    Reply With Quote  
     

  8. #8  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    Quote Originally Posted by Dexter Morgan View Post
    Mate you're doing it wrong.

    You have to do it in the correct order for the login procedure. What you are doing is you are sending a packet to a player that doesn't
    exist, and then in that method you register him..

    You clearly don't know what you are doing here and should go study other frameworks as this is pretty important and complicated.
    I've already tried it:

    Code:
    if (loginOpcode == 2) {
    			World.register(player);
    			PacketBuilder packetBuilder = new PacketBuilder();
    			packetBuilder.put((byte) loginOpcode);
    			packetBuilder.put((byte) player.getRights().ordinal());
    			packetBuilder.put((byte) 0);
    			player.getChannel().write(packetBuilder.toPacket());
    			player.getPacketSender().sendLogin();
    And besides the only thing that the register method does is add the player to a list.

    Well since I have common sense, I have looked at other frameworks: hyperion, runesource and lightrune.
    Reply With Quote  
     

  9. Thankful user:


  10. #9  
    Banned

    Join Date
    Mar 2011
    Posts
    4,062
    Thanks given
    194
    Thanks received
    689
    Rep Power
    0
    edit: managed to fool around with it a bit, and now not getting errors client-sided, just server (which I guess is progress in this case), now I'm getting this:

    Spoiler for New Errors:
    Code:
    	public static void parse(Session session, Packet packet) {
    		if (packet.getOpcode() == -1) {
    			return;
    		}
    		PacketListener packetListener = PacketTypes.packetListener[packet.getOpcode()];
    		if (packetListener == null) {
    			packetListener = new DefaultPacketListener();
    		}
    		System.out.println("Sending packet: " + PacketTypes.packetListener[packet.getOpcode()] + "; Opcode: " + packet.getOpcode());
    		try {
    			packetListener.execute(session.getPlayer(), packet);
    		} catch (Exception exception) {
    			System.out.println("Error sending packet: " + packet.getOpcode());
    		}
    	}
    
    Nov 03, 2012 8:33:43 PM org.niobe.Server main
    INFO: Port 43594 has been binded.
    Nov 03, 2012 8:33:59 PM org.niobe.model.world.World register
    INFO: Registering player: [T]; password: [ttttt]; Index: [0]
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 249
    Error sending packet: 249
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 134
    Error sending packet: 134
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 71
    Error sending packet: 71
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 104
    Error sending packet: 104
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 104
    Error sending packet: 104
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 104
    Error sending packet: 104
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 53
    Error sending packet: 53
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 53
    Error sending packet: 53
    Sending packet: org.niobe.net.packet.impl.SilencedPacketListener@627b5c; Opcode: 253
    Error sending packet: 253
    Nov 03, 2012 8:33:59 PM org.niobe.net.packet.impl.DefaultPacketListener execute
    INFO: Unhandled packet: 73; Packet size: 4
    Sending packet: null; Opcode: 73
    java.nio.channels.ClosedChannelException
    	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.cleanUpWriteBuffer(AbstractNioWorker.java:784)
    	at org.jboss.netty.channel.socket.nio.AbstractNioWorker.writeFromUserCode(AbstractNioWorker.java:507)
    	at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.handleAcceptedSocket(NioServerSocketPipelineSink.java:129)
    	at org.jboss.netty.channel.socket.nio.NioServerSocketPipelineSink.eventSunk(NioServerSocketPipelineSink.java:66)
    	at org.jboss.netty.channel.Channels.write(Channels.java:733)
    	at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.doEncode(OneToOneEncoder.java:71)
    	at org.jboss.netty.handler.codec.oneone.OneToOneEncoder.handleDownstream(OneToOneEncoder.java:60)
    	at org.jboss.netty.channel.Channels.write(Channels.java:712)
    	at org.jboss.netty.channel.Channels.write(Channels.java:679)
    	at org.jboss.netty.channel.AbstractChannel.write(AbstractChannel.java:248)
    	at org.niobe.model.world.Player.write(Player.java:146)
    	at org.niobe.net.packet.PacketSender.sendMapRegion(PacketSender.java:56)
    	at org.niobe.model.PlayerUpdating.update(PlayerUpdating.java:44)
    	at org.niobe.model.world.World.updateEntities(World.java:71)
    	at org.niobe.Server$1.execute(Server.java:64)
    	at org.niobe.task.Task.tick(Task.java:102)
    	at org.niobe.task.TaskScheduler.run(TaskScheduler.java:98)
    	at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    	at java.util.concurrent.FutureTask$Sync.innerRunAndReset(Unknown Source)
    	at java.util.concurrent.FutureTask.runAndReset(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(Unknown Source)
    	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	at java.lang.Thread.run(Unknown Source)
    Reply With Quote  
     


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. Buying a custom framework
    By Holocaust in forum Buying
    Replies: 4
    Last Post: 08-04-2012, 10:06 AM
  2. Replies: 1
    Last Post: 07-25-2012, 07:44 PM
  3. Arrav - Absolute Quality [Custom Framework]
    By ArravRSPS in forum Projects
    Replies: 79
    Last Post: 04-27-2012, 09:12 PM
  4. Custom Gameframe Framework!
    By Inside Sin in forum Graphics
    Replies: 17
    Last Post: 05-01-2009, 09:42 PM
  5. Custom framework.
    By Encouragin in forum Downloads
    Replies: 13
    Last Post: 09-23-2008, 09:58 PM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •