|
From: Wildern t. S. <tim...@ya...> - 2002-04-26 13:26:35
|
This is my version of the function "isValidName" for
LivingThing.java. "conf/dirtyWordFile" allows for real time
blocking of offensive patterns in character names.
The version in 2.7.3 restricts the players name to only letters.
I think this would eliminate a large portion of the current new dusk
population. I see nothing wrong with names like "death_god" and
"]V[agic". But I do agree that names like "_______" and "00043212"
are fairly unwanted. The strValid variable below can be adjusted to
contain whatever characters are allowed (remove the numbers if so
desired), and the "conf/dirtyWordFile" can include patterns like "__"
(a double underscore to force a single underscore between other valid
chars)
My version also puts a value in prefs to limit the length of
player names.
boolean isValidName(String strName)
{
if (strName == null)
return false;
if (strName.equals("")
|| strName.length() > namecap
|| (strName.toLowerCase().equals("god")
|| (strName.toLowerCase().equals("default")))
return false;
String strValid = "0123456789_]['#";
char[] letters = strName.toCharArray();
char[] validChars = strValid.toCharArray();
for(int n=0;n<letters.length;n++)
{
if (!Character.isLetter(letters[n]))
{
for(int i=0;i<validChars.length;i++)
{
if (letters[n] != validChars[i])
return false;
}
}
}
RandomAccessFile rafFile = null;
try
{
String strDirtyWord;
String strLowerCaseName = strName.toLowerCase();
rafFile = new RandomAccessFile("conf/dirtyWordFile",
"r");
strDirtyWord = rafFile.readLine();
while (strDirtyWord != null)
{
if (strLowerCaseName.indexOf(strDirtyWord) != -1)
{
rafFile.close();
return false;
}
strDirtyWord = rafFile.readLine();
}
rafFile.close();
}catch (Exception e)
{
System.out.println(strName + " had an error checking for
bad name in isBadName():"+e.toString());
return false;
}
return true;
}
__________________________________________________
Do You Yahoo!?
Yahoo! Games - play chess, backgammon, pool and more
http://games.yahoo.com/
|