[Help]y_ini saving case sensitive
#1

I noticed on my server for example you have a registered account name: John_Doe
then you tried to login to john_doe you can register it
How do a case insensitive upon registration on file checking? on windows there's no problem but on linux

Here's my code
PHP код:
    format(stringsizeof(string), "users/%s.ini"playername2);
    new 
FileUserFile fopen(stringio_read);
    if(
UserFile
Reply
#2

Yes, Linux is case sensitive while Windows isn't. You could lowercase the user's name before checking for their files (i.e. create and save them in lowercase only).
Reply
#3

but i already have a registered players so ican't lower case now

can i disable the case sensitive of linux?
Reply
#4

You can convert individual characters in a string to lowercase or uppercase:
To lower: https://sampwiki.blast.hk/wiki/Tolower
To upper: https://sampwiki.blast.hk/wiki/Toupper

Do you have an enforced naming convention on your server? i.e.: Firstname_Lastname? In that case, converting individual characters of the player's name is probably the way to go.

To answer your actual question: I don't know. I found a few solved questions on StackOverflow:
http://stackoverflow.com/questions/2...n-linux-server

But again, I advise you not to alter the way Linux' filesystem handles names and just use the method I proposed - it's also easier.
Reply
#5

Quote:

Do you have an enforced naming convention on your server? i.e.: Firstname_Lastname? In that case, converting individual characters of the player's name is probably the way to go.

No i dont have that? can you give me a script?
for the ff format:
Firstname_Lastname
First_N_Lastname
Like that?
Reply
#6

I quickly wrote one myself:
PHP код:
UsernameToLower(name[]) {
    new
        
loweredName[MAX_PLAYER_NAME],
        
tmp[MAX_PLAYER_NAME];
    for(new 
0strlen(name); <= ji++) {
        
tmp[i] = name[i];
        if(
name[i] >= 'A' && name[i] <= 'Z') {
            
tmp[i] = tolower(name[i]);
        }
        
strcat(loweredNametmp[i]);
    }
    return 
loweredName;

Tested with:
PHP код:
    printf("%s"UsernameToLower("Andy_S_Edeyn"));
    
printf("%s"UsernameToLower("AAAAndy_Sedeyn"));
    
printf("%s"UsernameToLower("andYseDeyn"));
    
printf("%s"UsernameToLower("ANDYSEDEYN")); 
EDIT: The function above will turn all characters in the given string to lowercase. I just realised that you told me that you're enforcing a certain naming convention on your server.

This function turns the starting character to an uppercase and every character preceded by an underscore (if they're not already). And it will turn every other character into lowercase, if they're not already:
PHP код:
UsernameToLower(name[]) {
    new
        
loweredName[MAX_PLAYER_NAME],
        
tmp[MAX_PLAYER_NAME];
    for(new 
0strlen(name); <= ji++) {
        
tmp[i] = name[i];
        if(
== && (name[i] <= 'A' || name[i] >= 'Z')) {
            
tmp[i] = toupper(name[i]);
        }
        else if(
name[i-1] == '_' && (name[i] <= 'A' || name[i] >= 'Z')) {
            
tmp[i] = toupper(name[i]);
        }
        else if(
name[i-1] != '_' && (name[i] >= 'A' || name[i] <= 'Z'))  {
            
tmp[i] = tolower(name[i]);
        }
        
strcat(loweredNametmp[i]);
    }
    return 
loweredName;

There's probably a more efficient way to write the code.

Tested with:
PHP код:
    printf("%s"UsernameToLower("Andy_S_edeyn"));
    
printf("%s"UsernameToLower("And_y_s_Edeyn"));
    
printf("%s"UsernameToLower("andyS_Ede_y_n"));
    
printf("%s"UsernameToLower("ANDY_S_EDEYN"));
    
printf("%s"UsernameToLower("ANDYSEDEYN"));
    
printf("%s"UsernameToLower("ANDY_s_EDEYN")); 
EDIT2: the trick to using this function is to use it when formatting the path.
Example:
PHP код:
UserPath(playerid) {
    new 
name[MAX_PLAYER_NAME], path[36];
    
GetPlayerName(playeridnamesizeof(name));
    
format(pathsizeof(path), USER_PATHUsernameToLower(name););
    return 
path;

This way it doesn't matter if the player's name is 'Andy_SEDEYN' or 'ANdY_sEdEYN'. The file will always be checked against: 'Andy_Sedeyn'.
Reply
#7

Andy thanks +rep man!
Reply
#8

This one is more faster and optimized:
PHP код:
UsernameToLower(const playername[MAX_PLAYER_NAME])
{
    new 
ln[MAX_PLAYER_NAME];
    for(new 
ii<strlen(playername); i++)
    {
        if(
playername[i] == '_') continue;
        if(
'A' playername[i] || playername[i] > 'Z') return playername;

        
ln[i] = tolower(playername[i]);
    }
    return 
ln;

By the way @AndySedeyn still giving a great help.
Reply
#9

thanks but i have a problem
PHP код:
format(sz_accStrsizeof(sz_accStr), "users/%s.ini"NickToLower(account_name));
    
printf(sz_accStr); 
it prints "users/.ini"

edit:
But when i print inside the function it works
PHP код:
NickToLower(nick[])
{
    for(new 
i=0j=strlen(nick); i<ji++)
    {
        
nick[i] = tolower(nick[i]);
    }
    
printf(nick);//it works
    
return nick;

Reply
#10

pawn Code:
new account_name[MAX_PLAYER_NAME];

GetPlayerName(playerid, account_name, MAX_PLAYER_NAME);
NickToLower(account_name);

printf("users/%s.ini", account_name);
You can convert all the current files from registered players using FileManager. dir_list function to loop through the files of a specific directory, checking if it is a file (FM_FILE) and if it is, rename the file.
Reply
#11

Quote:
Originally Posted by PRoleplay
Посмотреть сообщение
thanks but i have a problem
PHP код:
format(sz_accStrsizeof(sz_accStr), "users/%s.ini"NickToLower(account_name));
    
printf(sz_accStr); 
it prints "users/.ini"

edit:
But when i print inside the function it works
PHP код:
NickToLower(nick[])
{
    for(new 
i=0j=strlen(nick); i<ji++)
    {
        
nick[i] = tolower(nick[i]);
    }
    
printf(nick);//it works
    
return nick;

up this
Reply
#12

Quote:
Originally Posted by Dayrion
View Post
This one is more faster and optimized:
PHP Code:
UsernameToLower(const playername[MAX_PLAYER_NAME])
{
    new 
ln[MAX_PLAYER_NAME];
    for(new 
ii<strlen(playername); i++)
    {
        if(
playername[i] == '_') continue;
        if(
'A' playername[i] || playername[i] > 'Z') return playername;
        
ln[i] = tolower(playername[i]);
    }
    return 
ln;

By the way @AndySedeyn still giving a great help.
That code doesn't give the right results.

Tested with:
PHP Code:
    printf("1) %s"UsernameToLower("Andy_S_edeyn"));
    
printf("2) %s"UsernameToLower("And_y_s_Edeyn"));
    
printf("3) %s"UsernameToLower("andyS_Ede_y_n"));
    
printf("4) %s"UsernameToLower("ANDY_S_EDEYN"));
    
printf("5) %s"UsernameToLower("ANDYSEDEYN"));
    
printf("6) %s"UsernameToLower("ANDY_s_EDEYN")); 
Results:
Code:
[18:00:52] 1) Andy_S_edeyn
[18:00:52] 2) And_y_s_Edeyn
[18:00:52] 3) andyS_Ede_y_n
[18:00:52] 4) andy
[18:00:52] 5) andysedeyn
[18:00:52] 6) ANDY_s_EDEYN
Quote:
Originally Posted by PRoleplay
View Post
up this
Use the code I posted earlier:
PHP Code:
UsernameToLower(name[]) { 
    new 
        
tmp[MAX_PLAYER_NAME]; 
    for(new 
0strlen(name); <= ji++) { 
        
tmp[i] = name[i]; 
        if(
name[i] >= 'A' && name[i] <= 'Z') { 
            
tmp[i] = tolower(name[i]); 
        }
    } 
    return 
tmp

I removed the strcat step as it was redundant.

Tested with:
PHP Code:
    printf("1) %s"UsernameToLower("Andy_S_edeyn"));
    
printf("2) %s"UsernameToLower("And_y_s_Edeyn"));
    
printf("3) %s"UsernameToLower("andyS_Ede_y_n"));
    
printf("4) %s"UsernameToLower("ANDY_S_EDEYN"));
    
printf("5) %s"UsernameToLower("ANDYSEDEYN"));
    
printf("6) %s"UsernameToLower("ANDY_s_EDEYN")); 
Results:
Code:
[18:03:26] 1) andy_s_edeyn
[18:03:26] 2) and_y_s_edeyn
[18:03:26] 3) andys_ede_y_n
[18:03:26] 4) andy_s_edeyn
[18:03:26] 5) andysedeyn
[18:03:26] 6) andy_s_edeyn
Reply
#13

i place this on my onplayerconnect
PHP Code:
GetPlayerName(playeridplayernamesizeof(playername));
    
format(tempPnamesizeof(tempPname), "%s"playername);
    
format(playernamesizeof(playername), "%s%d"playername,playerid);
    
SetPlayerName(playeridplayername);
    
SetPlayerName(playeridUsernameToLower(tempPname)); 
Question: Do I need to setplayername twice? coz when i tried one setplayername it not change the name on tab

Another Question
PHP Code:
stock UsernameToLower(name[]) {

    new
        
loweredName[MAX_PLAYER_NAME+4],
        
tmp[MAX_PLAYER_NAME+4];

    for(new 
0strlen(name); <= ji++) {

        
tmp[i] = name[i];

        if(
== && (name[i] <= 'A' || name[i] >= 'Z')) {
            
tmp[i] = toupper(name[i]);
        }
        else if(
name[i-1] == '_' && (name[i] <= 'A' || name[i] >= 'Z')) {
            
tmp[i] = toupper(name[i]);
        }
        else if(
name[i-1] != '_' && (name[i] >= 'A' || name[i] <= 'Z'))  {
            
tmp[i] = tolower(name[i]);
        }
        
strcat(loweredNametmp[i]);
    }
    return 
loweredName;

names: John_Doe, it setname as john_Doe
Reply
#14

Quote:
Originally Posted by PRoleplay
View Post
...
You don't have to set the player's name. Use the 'UsernameToLower' function when checking the user's file:

PHP Code:
#define USER_PATH  "/users/%s.ini"
UserPath(playerid) {
    new 
name[MAX_PLAYER_NAME];
    
GetPlayerName(playeridnamesizeof(name));
    
format(pathsizeof(path), USER_PATHUsernameToLower(name));
    return 
path;

The function above is then used in for example the following situations:
PHP Code:
if(fexist(UserPath(playerid))) 
PHP Code:
INI_ParseFile(UserPath(playerid), "LoadUser_data", .bExtra true, .extra playerid);
// Change 'LoadUser_data' to whatever your function is called.
// And _'data' to whatever your filetag is. 
This line:
PHP Code:
format(pathsizeof(path), USER_PATHUsernameToLower(name)); 
Will turn the user's name into lowercase without actually changing their names. It then returns the path of the user's file in lowercase.
Reply
#15

@Andy no, My UserNametoLower function is not for converting all lowercase
its to forcing player to set theirname in proper roleplay that you've gave to me earlier

my problem now is when the player connects
it not change the tab name like for
ex. my samp name: jOhn_dOE
when i connect on my script i changed that on John_Doe but if you check it on tab your name doesn't changed

and one buggy thing some of my players doesn't convert their first later to uppercase
for ex. john_doe
then it change their name to john_Doe
Reply
#16

Quote:
Originally Posted by PRoleplay
View Post
@Andy no, My UserNametoLower function is not for converting all lowercase
its to forcing player to set theirname in proper roleplay that you've gave to me earlier

my problem now is when the player connects
it not change the tab name like for
ex. my samp name: jOhn_dOE
when i connect on my script i changed that on John_Doe but if you check it on tab your name doesn't changed

and one buggy thing some of my players doesn't convert their first later to uppercase
for ex. john_doe
then it change their name to john_Doe
Oh, I misunderstood you. I removed the strcat step from the first function:
PHP Code:
FixUsername(name[]) { 
    new 
        
tmp[MAX_PLAYER_NAME]; 
    for(new 
0strlen(name); <= ji++) { 
        
tmp[i] = name[i]; 
        if(
== && (name[i] <= 'A' || name[i] >= 'Z')) { 
            
tmp[i] = toupper(name[i]); 
        } 
        else if(
name[i-1] == '_' && (name[i] <= 'A' || name[i] >= 'Z')) { 
            
tmp[i] = toupper(name[i]); 
        } 
        else if(
name[i-1] != '_' && (name[i] >= 'A' || name[i] <= 'Z'))  { 
            
tmp[i] = tolower(name[i]); 
        } 
    } 
    return 
tmp

Tested with:
PHP Code:
    printf("1) %s"FixUsername("Andy_S_edeyn")); 
    
printf("2) %s"FixUsername("And_y_s_Edeyn")); 
    
printf("3) %s"FixUsername("andyS_Ede_y_n")); 
    
printf("4) %s"FixUsername("ANDY_S_EDEYN")); 
    
printf("5) %s"FixUsername("ANDYSEDEYN")); 
    
printf("6) %s"FixUsername("ANDY_s_EDEYN")); 
    
printf("7) %s"FixUsername("john_doe")); 
Results
Code:
[02:50:38] 1) Andy_S_Edeyn
[02:50:38] 2) And_Y_S_Edeyn
[02:50:38] 3) Andys_Ede_Y_N
[02:50:38] 4) Andy_S_Edeyn
[02:50:38] 5) Andysedeyn
[02:50:38] 6) Andy_S_Edeyn
[02:50:38] 7) John_Doe
EDIT: SetPlayerName is case-insensitive. That means that you can't change the player's name to the exact same name even when some characters are changed in case. You could bypass it by first giving the player another name and then changing it back to the fixed name.
Reply
#17

thanks again andy
PHP Code:
new playername[MAX_PLAYER_NAME+4],tempPname[MAX_PLAYER_NAME+4];
        
GetPlayerName(playeridplayernamesizeof(playername));
           
format(tempPnamesizeof(tempPname), "%s"playername);
        
format(playernamesizeof(playername), "%s%d"playername,playerid);
        
SetPlayerName(playeridplayername);
        
SetPlayerName(playeridUsernameToLower(playername)); 
my question is do i need to change the name to different and back it with the correct format ?
coz when i directly setname with format it not works

EDIT: another buggy when i check my name on tab it not change
but when i type/chat my name works fine
Reply
#18

@Andy i tried this John_James
it set the name as john_James
Reply
#19

Yep', wrong version given; sorry:
PHP Code:
UsernameToLower(const playername[MAX_PLAYER_NAME])
{
    new 
ln[MAX_PLAYER_NAME],
        
strl strlen(playername);

    for(new 
istrli++)
    {
        
ln[i] = playername[i];
        if(
playername[i] == '_') continue;
        
ln[i] = tolower(playername[i]);
    }
    return 
ln;

Reply
#20

Quote:
Originally Posted by PRoleplay
View Post
thanks again andy
PHP Code:
new playername[MAX_PLAYER_NAME+4],tempPname[MAX_PLAYER_NAME+4];
        
GetPlayerName(playeridplayernamesizeof(playername));
           
format(tempPnamesizeof(tempPname), "%s"playername);
        
format(playernamesizeof(playername), "%s%d"playername,playerid);
        
SetPlayerName(playeridplayername);
        
SetPlayerName(playeridUsernameToLower(playername)); 
my question is do i need to change the name to different and back it with the correct format ?
coz when i directly setname with format it not works

EDIT: another buggy when i check my name on tab it not change
but when i type/chat my name works fine
I edited my previous post and added this note:
Quote:
Originally Posted by AndySedeyn
View Post
EDIT: SetPlayerName is case-insensitive. That means that you can't change the player's name to the exact same name even when some characters are changed in case. You could bypass it by first giving the player another name and then changing it back to the fixed name.
Quote:
Originally Posted by PRoleplay
View Post
@Andy i tried this John_James
it set the name as john_James
That's odd. It works perfectly fine for me. Could you post the function you currently have?
EDIT: I added an extra check. Try this:
PHP Code:
FixUsername(name[]) {  
    new  
        
tmp[MAX_PLAYER_NAME];  
    for(new 
0strlen(name); <= ji++) {  
        
tmp[i] = name[i];  
        if(
== && (name[i] <= 'A' || name[i] >= 'Z')) {  
            
tmp[i] = toupper(name[i]);  
        }  
        else if(
name[i-1] == '_' && (name[i] <= 'A' || name[i] >= 'Z')) {  
            
tmp[i] = toupper(name[i]);  
        }  
        else if((
name[i-1] != '_' && != 0) && (name[i] >= 'A' || name[i] <= 'Z'))  {  
            
tmp[i] = tolower(name[i]);  
        }  
    }  
    return 
tmp;  

Also, I'm not entirely sure about this piece of code:
PHP Code:
new playername[MAX_PLAYER_NAME+4],tempPname[MAX_PLAYER_NAME+4];
        
GetPlayerName(playeridplayernamesizeof(playername));
           
format(tempPnamesizeof(tempPname), "%s"playername);
        
format(playernamesizeof(playername), "%s%d"playername,playerid);
        
SetPlayerName(playeridplayername);
        
SetPlayerName(playeridUsernameToLower(playername)); 
You seem to do more than you should be doing. Simply getting the player's name and then setting it should be enough. You don't necessarily have to make the user's temporary name something complicated. After all, they'll have it for less than half a second anyway.

Moreover, you don't need MAX_PLAYER_NAME + 4. The maximum length of a player's name is 20 characters anyway and MAX_PLAYER_NAME is already defined as 24.

Something along these lines would do:
PHP Code:
new playername[MAX_PLAYER_NAME];
GetPlayerName(playeridplayernamesizeof(playername));
SetPlayerName(playerid"TempName002"MAX_PLAYER_NAME);
SetPlayerName(playeridFixUsername(playername), MAX_PLAYER_NAME); 
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)