Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a flags update forward and a override param in set_user_flags #475

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

OciXCrom
Copy link
Contributor

Added a forward called "client_flags_updated" which will be called when the client's flags are modified using "set_user_flags" or "remove_user_flags". I also added another param in the "set_user_flags" function called "override", which if set to true will remove any other flags from the user - I found this necessary because the name of the function is "SET_user_flags", but it actually adds them to the current ones. This way coders can actually SET the flags instead of add them to the current ones.


pPlayer->flags[id] |= flag;

if(params[4])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to check for parameter availability here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I'm fairly new to this. How do I exactly add that check?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's an example

if (params[0] / sizeof(cell) >= 12)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it actually necessary? The 4th parameter has a default value of "false" if it's not used. Just curious why it's needed.

Copy link
Contributor

@WPMGPRoSToTeMa WPMGPRoSToTeMa Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OciXCrom you will need to recompile all plugins that using get_players.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OciXCrom Plugins that don't get compiled against the new *.inc will pass you 3 parameters, and core needs to handle that situation gracefully.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Nextra @Amaroq7 @WPMGPRoSToTeMa - Thanks, I added the necessary check.

Copy link
Contributor

@Amaroq7 Amaroq7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added some notes of mine and also as it has been said by @Nextra there's missing check.

@@ -1826,6 +1836,7 @@ native set_user_flags(index, flags = -1, id = 0);
*
* @param index Client index, 0 to set flags of server
* @param id Flag set id, ranging from 0 to 31
* @param override If set to true, all other flags will be removed
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Misplaced param's description.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, I always get confused when viewing .inc files because of the way the description is placed above the native. Fixed.

*
* @noreturn
*/
forward client_flags_updated(id, flags);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd also pass id of set here, so we'll know which set of flags has been updated.

Copy link
Contributor Author

@OciXCrom OciXCrom Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I never knew different sets of flag existed until I saw the actual .cpp file. Are different sets ever used? Because if not, it would be rather unnecessary to have to write the set argument every time we use the forward if we'll never have to use it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't have to write all params in forward, they can be skipped, so if someone doesn't depend on sets, they can safely omit last param.

Copy link
Contributor

@rsKliPPy rsKliPPy Jan 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I knew they existed but I never knew their purpose. The doc says:

AMXX stores multiple sets of flags internally, but only flag set
0 is actively used. You should not change the value of the third
parameter from the default.

I almost feel that we should just ignore flag sets and use a single one.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if AMXX doesn't use other values than 0, it still may be used by 3rd plugins for their some specific permission system, so they don't mess up with the AMXX's one. I think including that param wouldn't do much harm, but it's just my opinion.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Amaroq7 we can add it later if someone really uses sets.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually if they can really be skipped when using the forwards (haven't actually checked this), then there's really no problem if that param can be passed too. I'll check this tomorrow and add it if that's the case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Amaroq7 @rsKliPPy @WPMGPRoSToTeMa - I added the flag set as the last parameter in the forward, so people can skip it if not needed. I also passed the old flags so people can see which flags were changed.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Jan 9, 2018

I added a check whether the new flags are different from the old ones, since there's not really a point in executing the forward if they are the same.

@In-line
Copy link
Contributor

In-line commented Jan 9, 2018

I think something like bool addFlags = true will be more clear.

In the first place why does not set_user_flags override?
Perhaps deprecating set_user_flags and adding 2 more natives will be better?
add_user_flags,override_user_flags.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Jan 9, 2018

It should have added them in the first place, but it's too late now. I don't think there's really a point in deprecating it just because of the name.

@WPMGPRoSToTeMa
Copy link
Contributor

I think something like bool addFlags = true will be more clear.

Or SetFlagsMode:mode = SetFlagsMode_Add.

@OciXCrom
Copy link
Contributor Author

OciXCrom commented Jan 10, 2018

Hmm, I'm starting to like that idea. Maybe we can deprecate both set_user_flags and remove_user_flags and add a new one that will cover all 3 cases (set, add, remove) with the bool mentioned by @WPMGPRoSToTeMa. This bool can also be added to many other functions, e.g. set_user_health for easier usage. Any suggestions for the new flags function name?

@asherkin
Copy link
Member

This PR makes two independent changes, and you're talking about adding even more - each change should be a separate PR. I suggest retargeting this to be only the forward, and make a separate PR if you want to change how set_user_flags works.

@OciXCrom
Copy link
Contributor Author

Well, the PR is mainly about the forward, and the other change is just a small improvement to a function that's calling it. If I made them separate, one would become incompatible if the other one got merged, so I found it to be better this way. I won't be adding any more stuff until this gets approved (if it does). If it's really a problem I'll remove the set_user_flags change and make a separate PR after this one gets reviewed.

@twisterniq
Copy link
Contributor

@Arkshine will it be merged?

*
* @noreturn
*/
forward client_flags_updated(id, oldflags, newflags, set);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use same terminology that is used in set_user_flags?
Client ID is index
Set ID is just id

@voed
Copy link
Contributor

voed commented Nov 21, 2019

@Arkshine bump. Should it be splitted into 2 PRs?

@OciXCrom
Copy link
Contributor Author

@Arkshine if you wouldn't mind.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants