Thread: Ruse - Anti PID (Random character processing, disregards PID)

Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1 Ruse - Anti PID (Random character processing, disregards PID) 
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    WARNING:


    Quote Originally Posted by Professor Oak View Post

    To everyone who have added this snippet, you must make sure that your characters are probably synced.
    This basically means that you can not remove/add characters (players or npcs) whenever you want.
    Instead, you must add "requests" using queues or whatever, and add/remove the characters before the server updates.


    Something like this:

    Attached image

    ------------------------------------------

    Hey.

    Since I'm using the same CharacterList as Ruse, I figured I could release this small piece of code to the public.

    Quote from OSRS-wiki:
    When the server processes players, it goes through them each in turn. If you are first in the list, you get processed first. In early versions of Classic, you always got put at the end of the list (if I remember rightly), so if you stayed logged in you would end up at the beginning of the list eventually. Being processed first meant you could catch up with people more easily when following them, which gave an advantage particularly in the wilderness with PVP. A low PID means you were at the beginning of the list, high PIDs were at the end.

    This is no longer true, as you are now placed in a random place in the list and everyone else is shuffled up, so you don’t retain the same PID throughout your session. This makes things much fairer.

    — Game Engine Team
    Open CharacterList.java and add the following code however you want.
    I'd recommend keeping it clean!

    NOTE: The forEach method already exists. Make sure to replace it with mine.

    Code:
    	/**
    	 * This collections characters in a shuffled ArrayList.
    	 * Used for battling PID.
    	 */
    	private final List<E> shuffled_characters = new ArrayList<E>();
    
    	/**
    	 * Shuffles this collections list of characters.
    	 */
    	public void shuffle() {
    		shuffled_characters.clear();
    		
    		for (E e : characters) {
    			if (e == null)
    				continue;
    			shuffled_characters.add(e);
    		}
    		
    		Collections.shuffle(shuffled_characters);
    		
    	}
    
    	/**
    	 * {@inheritDoc}
    	 * <p>
    	 * This implementation will exclude all elements with a value of
    	 * {@code null} to avoid {@link NullPointerException}s.
    	 * 
    	 * 
    	 * 
    	 * UPDATED:
    	 * Now uses a shuffle_list to battle PID.
    	 * This means that all characters are always processed
    	 * in an random order instead of having higher priority
    	 * than other characters because of a higher PID.
    	 */
    	@Override
    	public void forEach(Consumer<? super E> action) {
    		
    		//Make sure both lists have the same size, otherwise
    		//we should re-shuffle.
    		if(size != shuffled_characters.size()) {
    			shuffle();
    		}
    		
    		//Perform the action on the shuffled characters
    		for(E e : shuffled_characters) {
    			if (e == null)
    				continue;
    			action.accept(e);
    		}
    	}
    Now open World.java and FIND this code:
    Code:
                    //Then we execute pre-updating code.
    		players.forEach(playerUpdate::executePreUpdate);
    		npcs.forEach(npcUpdate::executePreUpdate);
    ABOVE it, add this:
    Code:
    		//Now we shuffle our characters
    		//This will make sure each character gets processed 
    		//In a random order each cycle.
    		players.shuffle();
    		npcs.shuffle();
    And you should be done!

    Attached image
    As you can see it's now processing the players (and npcs) in a random order every cycle.
    Your server is now fairer, especially to stakers.


    I got the idea from Stuart's post back in 2014, click here for link.
    Honestly he deserves most credit, I simply made it work for Ruse-based servers.
    Reply With Quote  
     


  2. #2  
    Registered Member

    Join Date
    Nov 2015
    Age
    27
    Posts
    632
    Thanks given
    114
    Thanks received
    138
    Rep Power
    426
    Nice release, buddy. This should help many of the Ruse users out there!
    Reply With Quote  
     

  3. Thankful user:


  4. #3  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Quote Originally Posted by Tommy View Post
    Nice release, buddy. This should help many of the Ruse users out there!
    Thanks pal. Was more simple than I thought haha.
    Reply With Quote  
     

  5. #4  
    lol k


    Join Date
    Mar 2016
    Posts
    301
    Thanks given
    114
    Thanks received
    143
    Rep Power
    414
    Nice contribution, Oak i'm sure it will help some people.
    Reply With Quote  
     

  6. #5  
    Banned

    Join Date
    Jan 2011
    Posts
    1,904
    Thanks given
    367
    Thanks received
    330
    Rep Power
    0
    Nice release thanks!
    Reply With Quote  
     

  7. #6  
    Software Developer

    Tyrant's Avatar
    Join Date
    Jul 2013
    Age
    24
    Posts
    1,562
    Thanks given
    678
    Thanks received
    423
    Rep Power
    1060
    Only one thing that concerns me, how efficient is this way performance wise?
    How long would it take to shuffle a list of a couple hundred players, so would it effect the processing?

    Other then that, very nice
    Reply With Quote  
     

  8. #7  
    Respected Member


    Join Date
    Jan 2009
    Posts
    5,743
    Thanks given
    1,162
    Thanks received
    3,603
    Rep Power
    5000
    Quote Originally Posted by Tyrant View Post
    Only one thing that concerns me, how efficient is this way performance wise?
    How long would it take to shuffle a list of a couple hundred players, so would it effect the processing?

    Other then that, very nice
    Quote Originally Posted by Scu11 View Post
    shuffle is O(n ) so it is very cheap to perform
    Was answered on the original thread
    Reply With Quote  
     

  9. Thankful user:


  10. #8  
    Donator

    Jason's Avatar
    Join Date
    Aug 2009
    Posts
    6,092
    Thanks given
    2,402
    Thanks received
    2,823
    Rep Power
    4550
    Does CharacterList implement Iterable or Iterator? If so it might be worth updating those as well. It would be nice to see the same functionality from forEach in a traditional advanced for. None the less, great job on this.

    Code:
    for (Character character : characterList) {
       // random order
    }
    Reply With Quote  
     

  11. #9  
    Im an albatraoz

    Nand0's Avatar
    Join Date
    Feb 2010
    Age
    31
    Posts
    948
    Thanks given
    233
    Thanks received
    128
    Rep Power
    241
    randomly starts messing up the server for some reason not at the launch but after a few hours everone starts walking weird and than characters begin to null



    Looking for blazing fast and affordable vps or web hosting?
    AllGeniusHost



    Reply With Quote  
     

  12. #10  
    Extreme Donator


    Join Date
    Oct 2010
    Posts
    2,853
    Thanks given
    1,213
    Thanks received
    1,622
    Rep Power
    5000
    Quote Originally Posted by Nand0 View Post
    randomly starts messing up the server for some reason not at the launch but after a few hours everone starts walking weird and than characters begin to null
    Has never happened to me but the problem is probably because characters are added after the shuffle has been completed. This leads to some characters being skipped.
    To fix it, simply replace the forEach with this instead:

    Code:
    	/**
    	 * {@inheritDoc}
    	 * <p>
    	 * This implementation will exclude all elements with a value of
    	 * {@code null} to avoid {@link NullPointerException}s.
    	 * 
    	 * 
    	 * 
    	 * UPDATED:
    	 * Now uses a shuffle_list to battle PID.
    	 * This means that all characters are always processed
    	 * in an random order instead of having higher priority
    	 * than other characters because of a higher PID.
    	 */
    	@Override
    	public void forEach(Consumer<? super E> action) {
    		
    		//Make sure both lists have the same size, otherwise
    		//we should re-shuffle.
    		if(size != shuffled_characters.size()) {
    			shuffle();
    		}
    		
    		//Perform the action on the shuffled characters
    		for(E e : shuffled_characters) {
    			if (e == null)
    				continue;
    			action.accept(e);
    		}
    	}
    The only thing I added is this small part of code:
    //Make sure both lists have the same size, otherwise
    //we should re-shuffle.
    if(size != shuffled_characters.size()) {
    shuffle();
    }
    I've updated the post with the fixed forEach method aswell.
    Reply With Quote  
     

  13. 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. Characters getting Randomly Reset
    By Dreamsnake in forum Help
    Replies: 4
    Last Post: 09-16-2009, 08:16 PM
  2. Characters keep getting randomly erased
    By ncarug02 in forum Help
    Replies: 2
    Last Post: 06-20-2009, 01:02 PM
  3. [508]characters getting randomly erased
    By ncarug02 in forum Help
    Replies: 0
    Last Post: 06-18-2009, 02:08 AM
  4. Randomize Character Look
    By Naughty Panda in forum Configuration
    Replies: 12
    Last Post: 08-22-2008, 02:34 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
  •