Valhalla Legends Forums Archive | Battle.net Bot Development | Detecting if a username has an illegal character in it...

AuthorMessageTime
HeRo
How would I detect if a username has an illegal character in it?  When the bot recieves EID_SHOWUSER, I want it to add to the listview the usernames with illegal characters in it. Right now I have no idea where to start. Any positive tips would help, thanks.
April 23, 2006, 1:36 AM
Topaz
Instr()...
April 23, 2006, 2:07 AM
HeRo
Something like:

if instr(1,strusername,illy_character,vbTextCompare) then add user to list?
April 23, 2006, 2:30 AM
rabbit
Yes.
April 23, 2006, 3:16 AM
JoeTheOdd
[code] /**
Checks if a Battle.net account name is legal<br />
Make sure you remove @gateway, if it's there.<br />
If you're using D2, also remove the CharName* mangaling at the beginning
@author J
@param name Account name
@return Validity (boolean)
*/
boolean isLegalAccoutName(String name)
{
// Temporary variable declaration
boolean tempValid = false;

// Check length
if(name.length() !>= 3)
{
return false;
}

// Check if the first char is an alpha char
String legalFirstChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXZY";
for(int j = 0; j < legalFirstChars.length(); j++)
{
if(name.charAt(0) == legalFirstChars.charAt(j))
{
tempValid = true;
}
}
if(tempValid != true)
{
return false;
}

// Check if the rest are legal
String legalChars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890.[]-_()";
for(int i = 1; i < name.length(); i++)
{
tempValid = false;
for(int j = 0; j < legalChars.length(); j++)
{
if(name.charAt(i) == legalChars.charAt(j))
{
tempValid = true;
}
}
if(tempValid == false)
{
return false;
}
}
return true;
}[/code]

EDIT -
That's obviously not all the valid characters, but the algorithm is there.

EDIT -
Checking that first character is alpha, and checking length (thanks Frozen). I may have all the valid characters now.
April 23, 2006, 3:18 AM
FrOzeN
I just wrote this function, it should work for determining if it's an illy or not. There's probably an easier way to write this, I rushed it so eh..

Note that it doesn't have an error handling for usernames longer than 15 characters or a just 1 character. It treats them as legal names. Though, assuming you use this function correctly there isn't a need to have it handle them.

[code]Public Function IsIlly(Username As String) As Boolean
    If Len(Username) = 2 Then
        IsIlly = True
        'Username to short
    Else
        Dim strUsername As String, i As Integer, badChar As Boolean, strIllegal As String, strExtra As String
        strUsername = LCase(Username)
        strIllegal = "`~!@$^&=+|{};:',"
        strExtra = "-_()[]."
       
        If InStr(1, strExtra, Left(LCase(Username), 1)) <> 0 Then
            IsIlly = True
            'First character isn't letter/number
        Else
            For i = 1 To Len(strUsername)
                If InStr(1, strIllegal, Mid(strUsername, i, 1)) <> 0 Then
                    IsIlly = True
                    'Contains illegal character
                ElseIf InStr(1, strExtra, Mid(strUsername, i, 1)) <> 0 Then
                    If badChar <> False Then
                        IsIlly = True
                        'Two non-letter/number characters in a row.
                    Else
                        badChar = True
                    End If
                Else
                    badChar = False
                End If
            Next i
        End If
    End If
End Function[/code]

[EDIT] Slight clean up.
[EDIT 2] Added " | " to illegal character string.
April 23, 2006, 3:19 AM
HeRo
First time I got no negative replies, thank you all  ;D
April 23, 2006, 3:36 AM
JoeTheOdd
Oh yeah, forgot the negative reply.

Duh, you should know how to do this before writing a bot!

Heh, kidding.
April 23, 2006, 3:36 AM

Search