Thread: [Winterlove]: Fixing the notorious server-wide crash for Winterlove! (easy!)

Page 1 of 3 123 LastLast
Results 1 to 10 of 22
  1. #1 [Winterlove]: Fixing the notorious server-wide crash for Winterlove! (easy!) 
    brb ridin da storm

    blakeman8192's Avatar
    Join Date
    Dec 2012
    Age
    31
    Posts
    2,012
    Thanks given
    818
    Thanks received
    1,361
    Rep Power
    329
    Purpose:
    This tutorial will guide you to fix the notorious server-wide crash that every Winterlove-based server suffers from. This tutorial will eliminate the need for "server restarters" and other similar software.

    Difficulty
    Surprisingly, this tutorial is very easy to use. I would rate it about a 3/10.

    Let's get started!
    The main cause of crashes in Winterlove is a problem during the parsing process of incoming packets. Occasionally, a malformed packet will be received and this will cause a logic error to happen inside the PlayerHandler process() method. This will cause the main thread loop to exit, and the server shuts down. We will fix this by adding proper exception handling to the PlayerHandler class.

    Step 1: Add exception handling to the packet-parsing phase
    Find this block of code, inside PlayerHandler, in the process() method:
    Code:
    		for(int i = 0; i < maxPlayers; i++) {
    			if(players[i] == null || !players[i].isActive) continue;
    
    			players[i].actionAmount--;
    			players[i].preProcessing();
    			while(players[i].process());
    			players[i].postProcessing();
    			players[i].getNextPlayerMovement();
    
    			if(players[i].playerName.equalsIgnoreCase(kickNick))
    			{
    				players[i].kick();
    				kickNick="";
    			}
    			if(players[i].disconnected) {
    				if(saveGame(players[i])){ System.out.println("Game saved for player "+players[i].playerName); } else { System.out.println("Could not save for "+players[i].playerName); };
    				removePlayer(players[i]);
    				players[i] = null;
    			}
    		}
    Now, replace that chunk with the following chunk of code:
    Code:
    		for(int i = 0; i < maxPlayers; i++) {
    			if(players[i] == null || !players[i].isActive) continue;
    
    			try {
    				players[i].actionAmount--;
    				players[i].preProcessing();
    				while(players[i].process());
    				players[i].postProcessing();
    				players[i].getNextPlayerMovement();
    
    				if(players[i].playerName.equalsIgnoreCase(kickNick))
    				{
    					players[i].kick();
    					kickNick="";
    				}
    				if(players[i].disconnected) {
    					if(saveGame(players[i])){ System.out.println("Game saved for player "+players[i].playerName); } else { System.out.println("Could not save for "+players[i].playerName); };
    					removePlayer(players[i]);
    					players[i] = null;
    				}
    			} catch (Exception ex) {
    			}
    		}

    Step 2: Add exception handling to the player-updating phase:
    Find this block of code, inside PlayerHandler, in the process() method:
    Code:
    		for(int i = 0; i < maxPlayers; i++) {
    
    			if(players[i] == null || !players[i].isActive) continue;
    			if(players[i].disconnected) {
    				if(saveGame(players[i])){ System.out.println("Game saved for player "+players[i].playerName); } else { System.out.println("Could not save for "+players[i].playerName); };
    				removePlayer(players[i]);
    				players[i] = null;
    			}
    			else {
    				if(!players[i].initialized) {
    					players[i].initialize();
    					players[i].initialized = true;
    				}
    				else players[i].update();
    			}
    		}
    Now, replace that block of code with this block of code:
    Code:
    		for(int i = 0; i < maxPlayers; i++) {
    			try {
    				if(players[i] == null || !players[i].isActive) continue;
    
    				if(players[i].disconnected) {
    					if(saveGame(players[i])){ System.out.println("Game saved for player "+players[i].playerName); } else { System.out.println("Could not save for "+players[i].playerName); };
    					removePlayer(players[i]);
    					players[i] = null;
    				}
    				else {
    					if(!players[i].initialized) {
    						players[i].initialize();
    						players[i].initialized = true;
    					}
    					else players[i].update();
    				}
    			} catch (Exception ex) {
    			}
    		}
    You have just properly added exception handling to your Winterlove server. Now, when a malformed packet or other stream error occurs for a player, the player will disconnect/reconnect, but the server will not shut down and no other players will suffer.
    Enjoy.

    Credits: blakeman8192
    rest in peace Qemist, Izzy, Colton, TeChNo PuNk, Impulser, & bootnecklad
    Reply With Quote  
     

  2. #2  
    Registered Member
    Join Date
    Feb 2007
    Posts
    308
    Thanks given
    0
    Thanks received
    1
    Rep Power
    72
    I demand to have your babies.
    RuneWiki - The ultimate source of technical RuneScape information.
    Reply With Quote  
     

  3. #3  
    Registered Member

    Join Date
    Oct 2007
    Posts
    2,413
    Thanks given
    254
    Thanks received
    479
    Rep Power
    2785
    Who uses winterlove these days anyways, oh yeah that's right, everyone. Goodjob blake..
    Reply With Quote  
     

  4. #4  
    Banned

    Join Date
    Jan 2009
    Posts
    777
    Thanks given
    74
    Thanks received
    61
    Rep Power
    0
    So now the server will not crash after a certain amount of time ?
    Reply With Quote  
     

  5. #5  
    Member [Winterlove]: Fixing the notorious server-wide crash for Winterlove! (easy!) Market Banned


    Luke132's Avatar
    Join Date
    Dec 2007
    Age
    35
    Posts
    12,574
    Thanks given
    199
    Thanks received
    7,106
    Rep Power
    5000
    Quote Originally Posted by Torque View Post
    So now the server will not crash after a certain amount of time ?
    If the problems Blake said in this post are what is causing it to crash, then no.

    Attached imageAttached image
    Reply With Quote  
     

  6. #6  
    Registered Member pHametic's Avatar
    Join Date
    Nov 2006
    Posts
    637
    Thanks given
    3
    Thanks received
    1
    Rep Power
    11
    Nice, thanks for this.
    Reply With Quote  
     

  7. #7  
    Registered Member XiiL's Avatar
    Join Date
    Jul 2009
    Posts
    451
    Thanks given
    15
    Thanks received
    4
    Rep Power
    61
    Haha, thanks.
    Reply With Quote  
     

  8. #8  
    Registered Member
    Pride's Avatar
    Join Date
    Mar 2008
    Posts
    727
    Thanks given
    0
    Thanks received
    1
    Rep Power
    121
    I LOLED SO HARD!
    Never thought of that, Bit cheating but oh well

    Btw, at least add:

    ex.printStackTrace();

    Otherwise people who are coding won't know what hit them
    Reply With Quote  
     

  9. #9  
    Drag123451
    Guest
    Quote Originally Posted by Gnarly View Post
    Who uses winterlove these days anyways, oh yeah that's right, everyone. Goodjob blake..
    I do .

    Gj blake
    Reply With Quote  
     

  10. #10  
    Registered Member
    Enjoi's Avatar
    Join Date
    Sep 2008
    Posts
    2,451
    Thanks given
    566
    Thanks received
    282
    Rep Power
    1325
    Great job blake, thanks a ton.
    Reply With Quote  
     

Page 1 of 3 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
  •