Fixed behavior difference in SetPlayerName():#672
Fixed behavior difference in SetPlayerName():#672dev-karpov0 wants to merge 5 commits intoopenmultiplayer:masterfrom
Conversation
If the specified name has already been taken by player - it is set anyway, then native returns 1. (should 0 and the same name cannot be re-set). If name has already been taken by another player, native returns 0 (should -1).
| } | ||
|
|
||
| /// Makes Case Insensitive comparison of StringView strings | ||
| inline bool strIsEqualCI(const StringView& str1, const StringView& str2) |
There was a problem hiding this comment.
StringView should be passed by value, refer to CODING.md
| @@ -253,8 +253,21 @@ SCRIPT_API(ResetPlayerMoney, bool(IPlayer& player)) | |||
|
|
|||
| SCRIPT_API(SetPlayerName, int(IPlayer& player, const std::string& name)) | |||
There was a problem hiding this comment.
Maybe add SCRIPT_API_RETVAL(-1 here to return -1 if player is invalid
There was a problem hiding this comment.
Do you mean SCRIPT_API_FAILRET?
In SA:MP SetPlayerName returns 0 if player is invalid.
|
There's an error: is SA:MP if name is already taken by ANOTHER player - SetPlayerName returns 0. But the doc says -1 For backward compatibility, i think, the docs must be edited. |
|
Is there any reason you marked it as a draft? |
The samp doc itself says that but if you're sure the server does the opposite then yeah docs should be updated |
Yes, see comment above. Now (in last commit) SetPlayerName returns -1 if |
|
I have a question. |
Of course |
|
Now that we figured the docs are wrong, what does this PR fix? |
|
It fix ability to re-set the name that player already has.
|
I think that's deliberate to allow for changing upper and lower cases |
|
It is yes. Could maybe be even stricter and return 0 if the passed and current names are identical down to case, but then there's a semantic question: does |
I think it is necessary to proceed from the purpose of the function.
It's better, but backward compatibility will be broken. |
|
Maybe, if names are identical (with case) then return 0. |
|
Is the return value such an issue at all? Returning 1 when changing player name with only case sensitivity differences seems fine as the name is actually changed, don't see why it's an issue |
I fully agree with that - as you say, the name has changed. I was just thinking about the other situation of no case change at all. |
See this PR: openmultiplayer/open.mp#672
|
I created the PRs to update dosc in |
If the specified name has already been taken by player - it is set anyway, then native returns 1. (should 0 and the same name cannot be re-set).
If name has already been taken by another player, native returns 0 (should -1).
Docs