03.08.2016, 06:36
(
Последний раз редактировалось AndySedeyn; 03.08.2016 в 07:37.
)
I quickly wrote one myself:
Tested with:
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:
There's probably a more efficient way to write the code.
Tested with:
EDIT2: the trick to using this function is to use it when formatting the path.
Example:
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'.
PHP код:
UsernameToLower(name[]) {
new
loweredName[MAX_PLAYER_NAME],
tmp[MAX_PLAYER_NAME];
for(new i = 0, j = strlen(name); i <= j; i++) {
tmp[i] = name[i];
if(name[i] >= 'A' && name[i] <= 'Z') {
tmp[i] = tolower(name[i]);
}
strcat(loweredName, tmp[i]);
}
return loweredName;
}
PHP код:
printf("%s", UsernameToLower("Andy_S_Edeyn"));
printf("%s", UsernameToLower("AAAAndy_Sedeyn"));
printf("%s", UsernameToLower("andYseDeyn"));
printf("%s", UsernameToLower("ANDYSEDEYN"));
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 i = 0, j = strlen(name); i <= j; i++) {
tmp[i] = name[i];
if(i == 0 && (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(loweredName, tmp[i]);
}
return loweredName;
}
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"));
Example:
PHP код:
UserPath(playerid) {
new name[MAX_PLAYER_NAME], path[36];
GetPlayerName(playerid, name, sizeof(name));
format(path, sizeof(path), USER_PATH, UsernameToLower(name););
return path;
}