Block another characters (like ł,ć,ą etc..)

Started by rww, Apr 21, 2015, 08:51 PM

Previous topic - Next topic

rww

Sorry for post here , but LU forum is a litte dead (there is more scripters etc... and lu too have squirrel lang, and some testers from lu is there).

QuoteI need function for block another characters (like ł,ą,ć,ż,ę,ó etc..). My server use /changenick cmd and some players bugged account with invalid characters.

I very very thanks for help. I very need this, but idk how to do it.
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X

.

#1
For names or commands? Usually VC:MP cleans the names automatically, although I don't know about the commands. However, if this behavior is different on LU then you must specify. This can be fixed with a regular expression scan for un-needed characters or maybe some other methods. But I need to know where you need this. (if I remember correctly we've had this discussion once)
.

rww

Nice, works, but how to unlock: ^ = [ ]  etc...
Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X

Kratos_


Actually It looks me a bit contradicting since the codes S.L.C posted will block all non-alphanumeric characters from your code . And now you're asking to unlock ^ = [ ] which ofcourse are non-alphanumeric . If LU is following the same deal with nickname characters as VC:MP does ,  I mean changing everything unusual to underscore .  Then I would recommend to set a key ( a master password for changing an individual's nicknames ) into the new account & then transfer your account from previous one using this .
This way you will let the server to decide what to block without coding anything . You should wait for a LU individual for more refined response.
In the middle of chaos , lies opportunity.

Thijn

What you could try is loop through all characters and check if the ascii value is okay. Something like this:

local nick = "Tést";
for( local i = 0; i < nick.len(); i++ ) {
print(nick[i]);
if ( nick[i] < 0 || nick[i] > 127 ) {
print("Found invalid character " + nick[i] + " at position " + i);
}
}

EK.IceFlake

Quote from: Thijn on Apr 22, 2015, 05:58 AMWhat you could try is loop through all characters and check if the ascii value is okay. Something like this:

local nick = "Tést";
for( local i = 0; i < nick.len(); i++ ) {
print(nick[i]);
if ( nick[i] < 0 || nick[i] > 127 ) {
print("Found invalid character " + nick[i] + " at position " + i);
}
}
Better yet
    local nick = "Tést";
    local newnik = "";
    for( local i = 0; i < nick.len(); i++ ) {
        if ( nick[i] >= 0 || nick[i] <= 127 ) newnik[i] = nick[i];
    }
    player.Name = newnik;
Which will result in Tst and remove all invalid characters. This isnt tested though, so beware...

.

#6
Not quite the high performance approach but here you go:
// Same as bellow except pre-assembled
local _allowed_chars = [
 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
 112, 113, 114, 115, 116, 117, 118, 120, 121, 122, 65, 66, 67, 68, 69, 70,
 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86,
 88, 89, 90, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 91, 93, 123,
 125, 40, 41, 60, 62, 44, 46, 63, 59, 58
];

// This should be a static array like above
// to avoid parsing it every time in the function
local allowed = "";

allowed += "abcdefghijklmnopqrstuvxyz";
allowed += "ABCDEFGHIJKLMNOPQRSTUVXYZ";
allowed += "0123456789";
allowed += "[]{}()<>,.?;:";

function StrParse(s, f)
{
    // Could be cached as a pre-assembled global
    // if not changed at run-time (read above)
    local c = [];
    foreach (v in f) c.push(v);
   
    local a = [this, ""];
    // Actual filtering
    foreach (v in s) {
        if (c.find(v) != null) {
            a.push(v);
            a[1] += "%c";
        }
    }
   
    return ::format.acall(a);
}

// Let's give it a try
local name = StrParse("Y[o*]*<l^%)o$;293", allowed);

print(name);

Result after filtering:
Y[o]<l)o;293
This could be implemented as a plugin function to speed things up :D
.

rww

Join to Irrelevant Club Discord: https://discord.gg/MsPPZ5uV4X