Thread: Limit number of chars per IP

Page 1 of 5 123 ... LastLast
Results 1 to 10 of 45
  1. #1 Limit number of chars per IP 
    Donator

    tj007razor's Avatar
    Join Date
    Feb 2007
    Posts
    895
    Thanks given
    2
    Thanks received
    9
    Rep Power
    210
    Sorry about some of the formatting....

    Purpose: To limit the number of characters people are able to create per IP, to reduce number of chars in your folder by checking the number of chars on login.

    Difficulty: 1-3/10, depends

    Assumed Knowledge: basic java, ability to read, ctrl+f

    Server Base: old cheezescape, should work on all

    Classes Modified: client.java

    Procedure
    Step 1: First, create a new folder inside of your server folder called "IPs"

    Step 2: Now open client.java and declare these
    Code:
    public int numChars = 0; // number of chars saved in the file
    public static boolean killIt = false; // force disconnect?
    public boolean newChar = false; // is the player making a new char?
    
    //check the number of chars in the IP file
    public void checkipfiles()
    	{
    		try
    		{
    			BufferedReader in = new BufferedReader(new FileReader("IPs/"+connectedFrom+".txt"));
    			String data = null;
    			boolean charSaved = false;
    			numChars = 0;
    			while ((data = in.readLine()) != null)
    			{
    				numChars++;
    				if (data.matches(playerName))
    					charSaved = true; // is this players char saving in the IP file?
    			}
    			if (!charSaved && !newChar) { // if the char is not saved, save it, then count again
    				saveIP();
    				System.out.println(playerName+": char not saved to IP file! Saving.");
    				checkipfiles();
    			}
    		}
    		catch (IOException e) // error handling, file not found
    		{
    			System.out.println("Error when checking IP files: IP file not found.");
    			saveIP();
    		}
    	}
    public void saveIP() { // save the char to the player's IP file
    		BufferedWriter bw = null;
    		
          	try {
            	bw = new BufferedWriter(new FileWriter("IPs/"+connectedFrom+".txt", true)); // print the name in the player's IP.txt
    	 	bw.write(playerName);
    	 	bw.newLine();
    	 	bw.flush();
          	} catch (IOException ioe) {
    	 	System.out.println("Exception: File not found. File created.");
          	} finally {
    	 	if (bw != null) try {
    	    		bw.close();
    	 		} catch (IOException ioe2) {
    	    		sendMessage("Error logging IP file!");
    	 		}
          	}
    }
    Step 3: Now, we need to make it so upon login, it calls these.
    Search
    Code:
    public int loadGame(String playerName, String playerPass) {
    then inside that method find
    Code:
    misc.println(playerName+": character file not found.");
    You should see something like
    Code:
    } else if (File1 == false && File2 == false) {
    			misc.println(playerName+": character file not found.");
    			return 3;
    		}
    Change all that to
    Code:
    } else if (!(File1 || File2)) {
    			misc.println(playerName+": char ip not recorded.");
    			newChar = true;
    			checkipfiles(); // see how many chars are saved in the file
    			if (numChars < 3) saveIP(); // if there's less than 3 chars, save
    			if (numChars >= 3) { // if there's more than 3, disconnect it
    				killIt = true;
    				misc.println(playerName+": too many chars, disconnecting it.");
    			}
    			misc.println(playerName+": character file not found.");
    			return 3;
    		}
    Step 3: Finally, we need to be sure that the players get kicked before being saved if they have >= 3 chars.
    Find
    Code:
    public boolean process() {		// is being called regularily every 500ms
    and inside it add
    Code:
    //kick users before file saves if they have too many in the ip log.
    	if (killIt) {
    		logout();
    	}
    That should be it, post errors.

    Also, If you wish to tell people when they have reached the max number of chars in the IP file, find your login message towards the bottom of
    Code:
    public void initialize()
    and add
    Code:
    checkipfiles();
    if (numChars >= 3) {
    sendMessage("WARNING: You cannot make any new chars on this IP! You have used up all available slots.");
    }
    Credits: 100% me, tj007razor

    Vid:
    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ]
     

  2. #2  
    Donator

    Frosty Teh Snowman's Avatar
    Join Date
    Sep 2007
    Posts
    1,083
    Thanks given
    86
    Thanks received
    256
    Rep Power
    103
    good work. I will use later
     

  3. #3  
    codey
    Guest
    alot of people enjoy making several pures, have a main, perhaps a skiller all in one server, this may not be so practical but still useful.
     

  4. #4  
    Donator

    Frosty Teh Snowman's Avatar
    Join Date
    Sep 2007
    Posts
    1,083
    Thanks given
    86
    Thanks received
    256
    Rep Power
    103
    i will rep when i add this to my server tj007razor and codey, i click the first link in ur sig and posted!
     

  5. #5  
    Registered Member bloodychef's Avatar
    Join Date
    Dec 2007
    Posts
    207
    Thanks given
    0
    Thanks received
    0
    Rep Power
    27
    Code:
    client.java:35216: cannot find symbol
    symbol  : method saveIP()
    location: class client
                            if (numChars < 3) saveIP();
                                              ^
    Note: stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    1 error
    Press any key to continue . . .
    It seems you forgot the saveIP void (Method) please post it
     

  6. #6  
    Registered Member
    Join Date
    Nov 2007
    Posts
    21
    Thanks given
    0
    Thanks received
    0
    Rep Power
    1
    ok wow i got 100 errors when I placed this in... they are all right below where I entered this into my client.java and this is for the first part where you paste in the part that tells it to check at login... if you would like me to post all 100 of these errors just let me know cause it is alot...

    EDIT:
    nvm I had an extra closing bracket in there but i do have 1 error.... it is posted below.

    Code:
    client.java:30489: cannot find symbol
    symbol  : method saveIP()
    location: class client
                            if (numChars < 3) saveIP();
                                              ^
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    1 error
    Press any key to continue . . .
     

  7. #7  
    Registered Member bloodychef's Avatar
    Join Date
    Dec 2007
    Posts
    207
    Thanks given
    0
    Thanks received
    0
    Rep Power
    27
    Quote Originally Posted by Illuzion View Post
    ok wow i got 100 errors when I placed this in... they are all right below where I entered this into my client.java and this is for the first part where you paste in the part that tells it to check at login... if you would like me to post all 100 of these errors just let me know cause it is alot...

    EDIT:
    nvm I had an extra closing bracket in there but i do have 1 error.... it is posted below.

    Code:
    client.java:30489: cannot find symbol
    symbol  : method saveIP()
    location: class client
                            if (numChars < 3) saveIP();
                                              ^
    Note: Some input files use or override a deprecated API.
    Note: Recompile with -Xlint:deprecation for details.
    1 error
    Press any key to continue . . .
    Yep, its missing the void saveIP, just wait a while, he may post it.
     

  8. #8  
    Registered Member
    natsu's Avatar
    Join Date
    Apr 2007
    Age
    29
    Posts
    3,451
    Thanks given
    1,084
    Thanks received
    676
    Rep Power
    1096
    THX am gone use r3p++

    i get the same error i tink u forgot a void
     

  9. #9  
    Donator

    tj007razor's Avatar
    Join Date
    Feb 2007
    Posts
    895
    Thanks given
    2
    Thanks received
    9
    Rep Power
    210
    Quote Originally Posted by codey View Post
    alot of people enjoy making several pures, have a main, perhaps a skiller all in one server, this may not be so practical but still useful.
    For one thing, you can change the number it limits to. They can still make pures, however they will not be making 40 new accounts when they get the "already online" error, and other such instances people make new accounts and never playing again. Therefore limiting the number of lvl 3 noobs that were created and never used again.

    Also, sorry about forgetting teh saveIP method, added into step 2.

    [Only registered and activated users can see links. ]

    [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ] | [Only registered and activated users can see links. ]
     

  10. #10  
    Teh Joker
    Guest
    me 2 I have this error


    Help me lol



    client.java:32963: cannot find symbol
    symbol : method saveIP()
    location: class client
    if (numChars <= 3) saveIP();
    ^
    Note: stream.java uses or overrides a deprecated API.
    Note: Recompile with -Xlinteprecation for details.
    1 error
    - Server -
    .. Online!
     

Page 1 of 5 123 ... LastLast

Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Tags for this Thread

View Tag Cloud

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