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

Fix negative values being accepted in ban commands (solve issue #949) #953

Merged
merged 4 commits into from
Mar 13, 2024

Conversation

sunstep
Copy link
Contributor

@sunstep sunstep commented Mar 10, 2024

Description

The changes add a check on all ban commands to see whether the given duration is 0 or more. If the duration given is smaller than zero, it will tell the player and the ban will not proceed.

Motivation and Context

The motivation behind this pull request is that this fixes an open issue. Issue #949. According to the issue, banning with a negative time value is useless and only bans the player for the session. With this pull request banning with a negative value should not be possible anymore

How Has This Been Tested?

The changes have been tested on my own community server on a real player. When entering a negative value, we want the entire command to stop after giving the command issuer a warning. This approach should be valid and should not affect any other areas in the code. Values of 0 or higher have also been tested and these do get accepted by the command.

Screenshots (if appropriate):

image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have read the CONTRIBUTING document.

@sunstep sunstep mentioned this pull request Mar 10, 2024
@Rushaway
Copy link
Contributor

Rushaway commented Mar 11, 2024

You can keep it DRY with the existing code.

if (!StringToIntEx(buffer, time) || time < 0)
{
    ReplyToCommand(client, "%sUsage: sm_ban <#userid|name> <time|0> [reason]", Prefix);
    return Plugin_Handled;
}

Edit: Also please keep using tranlations, sourcebanspp is used by tons of users.

@sunstep
Copy link
Contributor Author

sunstep commented Mar 11, 2024

Implemented this way for the CommandBan function, will add more new commits soon

@Rushaway
Copy link
Contributor

It should also apply to every changes you made.

@sunstep
Copy link
Contributor Author

sunstep commented Mar 11, 2024

I don't see how it is possible in the other parts. The other parts don't print the right message after getting the int value of time. And since the minutes variable is used multiple times, wouldn't it be better there to just leave a separate check for if the time is negative or not?

Next to that, I can add translations for this phrase. But only when all other issues with the code I provided are resolved.

@Rushaway
Copy link
Contributor

Rushaway commented Mar 13, 2024

To avoid create new translations, we can just stick to the current command usage phrase.
Adjust the reply to cmd to the function ofc.

if (!StringToIntEx(time, minutes) || minutes < 0)
{
    ReplyToCommand(client, "%sUsage: sm_banip <#userid|name> <time> [reason]", Prefix);
    return Plugin_Handled;
}

The ban commands now do not accept negative ban values anymore while keeping the code dry as possible.
@sunstep
Copy link
Contributor Author

sunstep commented Mar 13, 2024

Done, the approach is now used for all commands.

@sunstep
Copy link
Contributor Author

sunstep commented Mar 13, 2024

By the way, should the sourcebans version be bumped? I decided not to do it, just in case. I can always add a commit if needed.

@Rushaway
Copy link
Contributor

LGTM.
No need to bump version, we will release a new version with all recent commits soon.

@Hackmastr
Copy link
Contributor

Thanks @Rushaway @sunstep!

@Hackmastr Hackmastr merged commit bf5303b into sbpp:php81 Mar 13, 2024
1 check passed
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.

None yet

3 participants