Thread: Okay Multi Support but...

Results 1 to 6 of 6
  1. #1 Okay Multi Support but... 
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    I think the picture explains but the problem is, on the account logging in I don't see the person already in, but on account that is logged in I see the dude logging in.

    Confusion



    Upto date code:

    Code:
    public static void update(Player p) {
            StaticPacketBuilder mainPacket = new StaticPacketBuilder().setId(81)
                .setSize(Size.VariableShort).initBitAccess();
            StaticPacketBuilder updateBlock = new StaticPacketBuilder().setBare(true);
            
            updateThisPlayerMovement(p, mainPacket);
            
            if(p.getUpdateFlags().isUpdateRequired()) {
                appendUpdateBlock(p, updateBlock, false);
            }
            
            mainPacket.addBits(8, p.getPlayerListSize());
            int size = p.getPlayerListSize();
            
            p.setPlayerListSize(0);//Reset size and rebuild it straight away
            boolean[] newPlayer = new boolean[Constants.PLAYER_CAP];
            
            for (int i = 0; i < size; i ++) {
                if(p.getPlayerList()[i] == null || //If player is null
                        p.getPlayerList()[i].isDisconnected() || //If player disconnected 
                        !p.getPlayerList()[i].getLocation().withinDistance(p.getLocation()) ||
                        //If player isn't in distance
                        p.getPlayerList()[i].getUpdateFlags().didTeleport()) { //If player teleported
                    if(p.getPlayerList()[i] != null) { //If player isn't null anymore
                        p.getPlayersInList()[p.getPlayerList()[i].getIndex()] = 0;//Set the player index to 0?
                    }
                    mainPacket.addBits(1, 1);//1 bit of data
                    mainPacket.addBits(2, 3);//3 bits of data
                } else {
                    updatePlayerMovement(p.getPlayerList()[i], mainPacket);
                    p.getPlayerList()[p.getPlayerListSize()] = p.getPlayerList()[i];
                    p.setPlayerListSize(p.getPlayerListSize()+1);
                }
            }
            
            for(Player p2 : World.getInstance().getPlayerList()) {
                if(p2 == null || p2.getIndex() == p.getIndex()) {
                    continue;
                }
                if(p.getPlayersInList()[p2.getIndex()] == 1 || !p2.getLocation().withinDistance(p.getLocation())) {
                    continue;
                }
                newPlayer[p.getPlayerListSize()] = true;
                addNewPlayer(p, p2, mainPacket, updateBlock);
            }
            
            if(updateBlock.getLength() > 0) {
                mainPacket.addBits(11, 2047);
            }
            mainPacket.finishBitAccess();
            if(updateBlock.getLength() > 0) {
                mainPacket.addBytes(updateBlock.toPacket().getData());
            }
            p.getSession().write(mainPacket.toPacket());
        }
        
        private static void addNewPlayer(Player p, Player p2, StaticPacketBuilder mainPacket, StaticPacketBuilder updateBlock) {
            p.getPlayersInList()[p2.getIndex()] = 1;
            p.getPlayerList()[p.getPlayerListSize()] = p2;
            p.setPlayerListSize(p.getPlayerListSize()+1);
            mainPacket.addBits(11, p2.getIndex());
            int yPos = p2.getLocation().getY() - p.getLocation().getY();
            int xPos = p2.getLocation().getX() - p.getLocation().getX();
            if(xPos < 0) {
                xPos += 32;
            }
            if(yPos < 0) {
                yPos += 32;
            }
            mainPacket.addBits(1, 1);
            appendUpdateBlock(p2, updateBlock, false);
            mainPacket.addBits(1, 1);
            mainPacket.addBits(5, yPos).addBits(5, xPos);
        }
        
        private static void updatePlayerMovement(Player p, StaticPacketBuilder mainPacket) {
            if (p.getSprites().getPrimarySprite() == -1) { //No movement.
                if(p.getUpdateFlags().isUpdateRequired() || 
                        p.getUpdateFlags().isChatTextUpdateRequired()) {
                    mainPacket.addBits(1, 1);
                    mainPacket.addBits(2, 0);
                } else {
                    mainPacket.addBits(1, 0);
                }
            } else if(p.getSprites().getSecondarySprite() == -1) { //Walking
                mainPacket.addBits(1, 1);
                mainPacket.addBits(2, 1);
                mainPacket.addBits(3, p.getSprites().getPrimarySprite());
                mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() || p.getUpdateFlags().isChatTextUpdateRequired() ? 1 : 0);
            } else { //Running
                mainPacket.addBits(1, 1);
                mainPacket.addBits(2, 2);
                mainPacket.addBits(3, p.getSprites().getPrimarySprite());
                mainPacket.addBits(3, p.getSprites().getSecondarySprite());
                mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() || p.getUpdateFlags().isChatTextUpdateRequired() ? 1 : 0);
            }
        }
    and :
    Code:
    private static void updateThisPlayerMovement(Player p, StaticPacketBuilder mainPacket) {
            if(p.getUpdateFlags().didMapRegionChange()) {
                p.getActionSender().sendMapRegion();
            }
            if (p.getUpdateFlags().didTeleport()) {
                mainPacket.addBits(1, 1);
                mainPacket.addBits(2, 3); //Update type 3
                mainPacket.addBits(2, p.getLocation().getZ()); //Height 
                mainPacket.addBits(1, 1); //Discard walking queue.
                mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() ? 1 : 0); //Updates required
                mainPacket.addBits(7, p.getLocation().getLocalY()); //Local Y
                mainPacket.addBits(7, p.getLocation().getLocalX()); //Local X
            } else {
                if(p.getSprites().getPrimarySprite() == -1) {
                    mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() ? 1 : 0);
                    if(p.getUpdateFlags().isUpdateRequired()) {
                        mainPacket.addBits(2, 0);
                    }
                } else {
                    if(p.getSprites().getSecondarySprite() != -1) {
                        mainPacket.addBits(1, 1);
                        mainPacket.addBits(2, 2);
                        mainPacket.addBits(3, p.getSprites().getPrimarySprite());
                        mainPacket.addBits(3, p.getSprites().getSecondarySprite());
                        mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() ? 1 : 0);
                    } else {
                        mainPacket.addBits(1, 1);
                        mainPacket.addBits(2, 1);
                        mainPacket.addBits(3, p.getSprites().getPrimarySprite());
                        mainPacket.addBits(1, p.getUpdateFlags().isUpdateRequired() ? 1 : 0);
                    }
                }
            }
        }
    Reply With Quote  
     

  2. #2  
    Renown Programmer and Respected Member
    Maxi's Avatar
    Join Date
    Jun 2008
    Posts
    3,197
    Thanks given
    281
    Thanks received
    1,095
    Rep Power
    1366
    Loop trough the player list when someone is login in and do a reqplayerupdate or something like that.
    Reply With Quote  
     

  3. #3  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    I am missing something I know but I am unsure what that is.
    Reply With Quote  
     

  4. #4  
    Member
    Nour's Avatar
    Join Date
    May 2007
    Posts
    472
    Thanks given
    127
    Thanks received
    61
    Rep Power
    569
    try iterating through your list of players and calling update for each one within the map region of the character that just logged in.
    RIP Emps-scape 2006-2013.
    [SPOIL]
    [/SPOIL]

    i need 2 herd sum bots
    i need 2 steal sum zombies
    i need 2 open many slots
    to hold my ****in zombies
    Reply With Quote  
     

  5. #5  
     

    Vastiko's Avatar
    Join Date
    Dec 2006
    Posts
    5,700
    Thanks given
    300
    Thanks received
    663
    Rep Power
    5000
    Fixed it, it was to do with me not calling force send of appearance when initiating a new player

    ---------- Post added at 07:48 PM ---------- Previous post was at 07:45 PM ----------

    God dam it now I don't recieve the chat text packet
    Reply With Quote  
     

  6. #6  
    Registered Member
    Kelvin's Avatar
    Join Date
    Jun 2007
    Posts
    1,433
    Thanks given
    48
    Thanks received
    33
    Rep Power
    269
    Update also their updateBlocks.
    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

Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •