[HELP] Roleplay character name check function - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [HELP] Roleplay character name check function (
/showthread.php?tid=664955)
[HELP] Roleplay character name check function -
JesterlJoker - 17.03.2019
PHP код:
checkName(playerid, name[]){
new find = strfind(name, "_", false);
if(find == 0) return playerDialogs(playerid, USERNAMEINVALID_DIALOG), 0;
for(new i, j = strlen(name); i < j; i++){
if(i == find) continue; // skips '_' character from being checked
else if(i == 0){
if(name[i] >= 'A' && name[i] <= 'Z') continue;
else {playerDialogs(playerid, FIRSTNAMENOTCAP_DIALOG); break;}
}else if(i == find+1){
if(name[i] >= 'A' && name[i] <= 'Z') continue;
else {playerDialogs(playerid, LASTNAMENOTCAP_DIALOG); break;}
}else{
if(name[i] >= 'a' && name[i] <= 'z') continue;
else if(name[i] >= 0 && name[i] <= 9) {playerDialogs(playerid, USERNAMEHASNUMBER_DIALOG); break;}
else {playerDialogs(playerid, USERNAMESPECIALCHARS_DIALOG); break;}
}
}
inline characterCheck(){
if(cache_num_rows() != 0){
cache_get_value(0, "password", playerData[playerid][password], MAX_PASSWORD);
cache_get_value(0, "salt", playerData[playerid][salt], MAX_SALT);
playerDialogs(playerid, LOGIN_DIALOG);
}else{
playerDialogs(playerid, REGISTER_DIALOG);
}
}
new query[38 + MAX_USERNAME + 13];
mysql_format(db, query, sizeof query, "SELECT * FROM %e WHERE username = '%e'",
USER_TABLE, playerData[playerid][username]);
mysql_tquery_inline(db, query, using inline characterCheck);
return 1;
}
Just need a clarification on this code if does this work or not, I can't try this yet since I'm not on proper pc.
I just need to check if :
Код:
the username can be checked with '_'
Код:
caps on both lastname and firstname which looks like this Ross_Weis
Код:
check if there are numbers
Код:
finally if there are special chars.
I will not say that this is mine but the idea was brought up from many and many name checks I've seen out there...
This is for my server and since I'm a security check freak... and a security perfectionist... I wish this fully working for my server...
Dislaimer:
I also have not searched the forum so much to see if this has been already been made or not...
the username has already been fetch on OnPlayerConnect so that's already not a problem...