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. ]
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
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 . . .
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.
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. ]
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!