Thread: Stopping Non Client Connections!

Page 1 of 3 123 LastLast
Results 1 to 10 of 26
  1. #1 Stopping Non Client Connections! 
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Purpose: A small fix-up for the server class.

    About: This will pretty much stop non-client connections.(And SYI)

    First off go into your run method in the client class and remove ...

    Code:
    if(inStream.readUnsignedByte() != 14) {
    disconnected = true;
    PlayerHandler.players[playerId] = null;
    return;
    }
    This is what causes most nullers to well ... null.

    Then the server fix up editing the run method ...

    What the code above should do is check for byte 14 to see if it's an actual client connecting.

    But instead of checking if it's an actual client or not AFTER everything is already set up, we check it at the socket level. We're using a switch because it's a lot neater than a bunch of if statements. What the below code will do is if a client is connecting, checks for a value of 14, it creates a new player, if a non-client is connecting, value isn't 14, it will close the socket. Look at these two images ...

    What we SHOULDN'T be doing ...



    What we SHOULD be doing ...




    To make this work just add this where you deleted the if statement.
    Code:
    while(true) {
    java.net.Socket s = clientListener.accept();
    s.setTcpNoDelay(true);
    String connectingHost = s.getInetAddress().getHostName();
    if(clientListener != null) {
    InputStream input_ = s.getInputStream();
    switch(input_.read()){ // switches the InputStream
    /* Client connecting */
    case 14: // what it should be
    playerHandler.newPlayerClient(s, connectingHost); // connected
    break;
    /* Non-client connecting or general error */
    default: // catches anything that shouldn't be happening
    s.close(); // doesn't let it connect
    break;
    }
    } else {
    s.close();
    }
    }
    That pretty much wraps it up.
    For any questions ask me.
    This is a member of my forums work.
    He gave me permission
     

  2. #2  
    twichdoublez
    Guest
    is this a website where u can play the game sorta like runescape
     

  3. #3  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Quote Originally Posted by twichdoublez View Post
    is this a website where u can play the game sorta like runescape
    Wtf?
    Why are you posting on my thread.
    That is what the help section is for.
     

  4. #4  
    deathdroid old
    Guest
    OOOH nice thank you
     

  5. #5  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    No porblem glad to help
     

  6. #6  
    Registered Member
    Shamon King's Avatar
    Join Date
    Aug 2007
    Posts
    3,336
    Thanks given
    90
    Thanks received
    228
    Rep Power
    1363
    i get unreachable statement with the while(true)
    and i deleted it and the last bracket and got no errors
    so im guessing that fixed it?

    nope doesnt allow me to log on
     

  7. #7  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Take it out. I will check it out and see what is wrong.
    It worked for like 10 other people though.....
     

  8. #8  
    Ian...
    Guest
    Nice work Ill use it
     

  9. #9  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    Cool veteran is going to use my stuff.
    Does that mean i get an auto jew star.
    Wait I should get one cause I am jewish!
     

  10. #10  
    42
    42 is offline
    Banned

    Join Date
    Feb 2008
    Age
    26
    Posts
    999
    Thanks given
    1
    Thanks received
    11
    Rep Power
    0
    You don't have the if statement add it to your run method.
     

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
  •