[Help]y_ini saving case sensitive
#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


Messages In This Thread

Forum Jump:


Users browsing this thread: 2 Guest(s)