Thread: Bug Fix: Player Processing (Stop Mass clicking affecting your updating speeds!)

Page 1 of 9 123 ... LastLast
Results 1 to 10 of 81
  1. #1 Bug Fix: Player Processing (Stop Mass clicking affecting your updating speeds!) 
    Registered Member
    Unborn's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    516
    Thanks given
    1
    Thanks received
    3
    Rep Power
    317
    Purpose: To stop mass clicking completely, and give your server a steady processing time.

    Description: This tutorial will show you how to fix a major bug I have recently discovered the cause of, in which mass clicking would affect the speed your server would process it's clients.
    In simple english - Stop Mass clicking from affecting your 'timers'.


    Difficulty: About 3.5, I don't think I explained it too well.

    Assumed Knowledge: Opening Files, Copying and Pasting, Deleting.

    Tested Server: Winterloves

    Files/Classes Modified: PlayerHandler.java, Player.java, client.java

    Procedure
    Step 1 - Make sure your client.java can handle the updates to its method of processing:
    Open up your client.java. Search for the following:
    Code:
    private boolean packetProcess()
    If you DO have the above code:
    • Replace the word private, with public .
    • Scroll up a bit, until you see 'return packetProcess();'. Replace that with 'return false;'.
    • Skip ahead to step 4.

    If you DON'T have the above code, complete steps 2 and 3


    Step 2 - Removing the old packet processing method:
    Ok, so you don't have a seperate method for processing packets. Not to worry, I'll show you how to make one.

    Search for:
    Code:
    void parseIncomingPackets()
    A short while above that, you should see something like the following - in your process method.
    Code:
            if(disconnected) return false;
            try {
                if(timeOutCounter++ > 20) {
                    actionReset();
                    disconnected = true;
                    return false;  }
        
                if(in == null) return false;
    
                int avail = in.available();
                if(avail == 0) return false;
                if(packetType == -1) {
                    packetType = in.read() & 0xff;
                    if(inStreamDecryption != null)
                        packetType = packetType - inStreamDecryption.getNextKey() & 0xff;
                    packetSize = packetSizes[packetType];
                    avail--;  }
                if(packetSize == -1) {
                    if(avail > 0) {
                        packetSize = in.read() & 0xff;
                        avail--; }
                    else return false; }
                if(avail < packetSize) return false;
                fillInStream(packetSize);
                timeOutCounter = 0;
    
                parseIncomingPackets();    
                packetType = -1;
            } catch(java.lang.Exception __ex) {    __ex.printStackTrace();  disconnected = true;
                      System.out.println("UnScape Server [fatal] - exception"); }
            return true;
    Delete all of that, from (and including)
    Code:
            if(disconnected) return false;
            try {
    until (and including)
    Code:
    return true;
    In its place, add the following:
    Code:
    return false;
    Note that the actual code will vary between servers, as boolean process is probably the most edited method by beginners.


    Step 3 - Creating the new packet processing method:
    Ok, so you didn't have a spearate packet processing method, and you have just deleted the packet processing method which was built into your boolean process.

    Now, we need to create a new packet processing method.
    Firstly, find the following again:
    Code:
    void parseIncomingPackets()
    Add the following, above the line you just found.
    Code:
        public boolean packetProcess() {
            try {
                if(timeOutCounter++ > 20) {
                    misc.println("Disconnected "+playerName+", Data transfer timeout.");
                    disconnected = true;
                    return false;
                }
                if(in == null) return false;
                int avail = in.available();
                if(avail == 0) return false;
    
                if(packetType == -1) {
                    packetType = in.read() & 0xff;
                    if(inStreamDecryption != null)
                        packetType = packetType - inStreamDecryption.getNextKey() & 0xff;
                    packetSize = packetSizes[packetType];
                    avail--;
                }
                if(packetSize == -1) {
                    if(avail > 0) {
                        packetSize = in.read() & 0xff;
                        avail--;
                    }
                    else return false;
                }
                if(avail < packetSize) return false;
                fillInStream(packetSize);
                timeOutCounter = 0;
                parseIncomingPackets();
                packetType = -1;
            } catch(java.lang.Exception __ex) {
                misc.println("Exception encountered while parsing incoming packets from "+playerName+".");
                __ex.printStackTrace(); 
                disconnected = true;
            }
            return true;
        }
    Ok, now you should be ready to move on to the next steps.


    Step 4 - Allowing Abstract access to the packetProcess Method:
    Save and Close client.java, and open up Player.java.
    Search for the following:
    Code:
    public abstract boolean process();
    Below that, add this:
    Code:
    public abstract boolean packetProcess();
    Save and close Player.java.


    Step 5 - Changing the way clients are processed:
    Ok, open up PlayerHandler.java and search for the following:

    Code:
    players[i].preProcessing();
    while(players[i].process());
    players.postProcessing();
    

    Replace that with (Updated):
    Code:
    try { 
    	players[ i ].preProcessing();
    	players[ i ].process();
    	int PacketLimit = 10;
    	while(players[ i ].packetProcess() && PacketLimit-- >= 0);
    	players[ i ].postProcessing();
    } catch(Exception e) { players[ i ].disconnected = true; }

    Save and close PlayerHandler, compile & restart your server, and you're done.


    The Bug - Explained
    Ok, I'll explain a little bit about this bug.
    What happened was, every time the client sends data to the server to tell it what it is doing, the server would loop through all of the different packets and process the player aswell as the packet for each one received.
    As most of you who program private servers add things to the client process, thinking the server processes it every half second, when infact it indeed processes it approximately every half second, but also when multiple packets are recieved. This causes certain scripts to be executed ahead of when you wanted them to be, and can be quite frustrating.
    This tutorial replaces the old method of processing a player (continuously processing the player until all of the received packets have been parsed) with a new one, in which it first processes the player, and then loops through the recieved packets until they have all been parsed.



    Credits: All credits to me (Unborn).

    Note: This tutorial was created on this page, based on an edit made by myself to my server.
    If any errors are encountered, please let me know.
    I apologize for any parts of this tutorial which are not easily understandable.
    Please post any comments you have on this tutorial, I would like to hear them all.


     

  2. #2  
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    Well, I get a error

    Code:
    PlayerHandler.java:138: cannot find symbol
    symbol  : method processPackets()
    location: class Player[]
    while(players.processPackets());
                 ^
    PlayerHandler.java:139: cannot find symbol
    symbol  : method postProcessing()
    location: class Player[]
    players.postProcessing();
           ^
    Note: stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    2 errors
    Druk op een toets om door te gaan. . .
     

  3. #3  
    Registered Member
    Unborn's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    516
    Thanks given
    1
    Thanks received
    3
    Rep Power
    317
    Hey, sorry.
    There appears to be a problem with the BBC (Bulletin Board Code) which will not display the correct code.
    It should be replaced with:
    Code:
    players[i].preProcessing();
    players[i].process();
    while(players[i].packetProcess());
    players[i].postProcessing();
    EDIT: I have changed added spaces to the code in the tutorial, it looks worse but atleast the forum actually displays the [ i ] part now.

    -Unborn


     

  4. #4  
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    Works Now, Thanks Oh Btw nice tut =P
     

  5. #5  
    Registered Member
    Unborn's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    516
    Thanks given
    1
    Thanks received
    3
    Rep Power
    317
    No Problems, Thanks for actually posting.

    -Unborn


     

  6. #6  
    Ian...
    Guest
    Very nice work. Every server needs this
     

  7. #7  
    Registered Member
    Unborn's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    516
    Thanks given
    1
    Thanks received
    3
    Rep Power
    317
    Thanks for posting.
    I agree, every server should have this.

    By the way, did you guys already have the packetProcess method?

    -Unborn


     

  8. #8  
    Registered Member

    Join Date
    Sep 2007
    Posts
    585
    Thanks given
    8
    Thanks received
    7
    Rep Power
    98
    I have it in my server

    I guess the most servers has it
     

  9. #9  
    Registered Member
    Unborn's Avatar
    Join Date
    Dec 2007
    Age
    28
    Posts
    516
    Thanks given
    1
    Thanks received
    3
    Rep Power
    317
    Ok.
    I decided to add the steps for creating it anyway, because the blank winterloves source didn't have it...
    I think most sources have it already though.

    -Unborn


     

  10. #10  
    Ian...
    Guest
    In most wL sources the packetProcess method is just above parceIncomingPackets method, even if they dont u still have it coverd in your tutorial. Its well written, keep it up.

    - Ian...
     

Page 1 of 9 123 ... LastLast

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
  •