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

WIP - Lowercase cleanup #1706

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

WIP - Lowercase cleanup #1706

wants to merge 2 commits into from

Conversation

sgdc3
Copy link
Member

@sgdc3 sgdc3 commented Dec 7, 2018

Tests needs to be adapted accordingly, any feedback?

Tests needs to be adapted accordingly
@sgdc3 sgdc3 requested review from ljacqu and hex3l December 7, 2018 11:28
Copy link
Member

@ljacqu ljacqu left a comment

Choose a reason for hiding this comment

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

I was skeptical when I saw this, but this actually constitutes a really nice clean up. Thanks man :)

}

purgeService.purgePlayers(sender, namedBanned, bannedPlayers.toArray(new OfflinePlayer[bannedPlayers.size()]));
purgeService.purgePlayers(sender, namedBanned, bannedPlayers.toArray(new OfflinePlayer[0]));
Copy link
Member

Choose a reason for hiding this comment

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

Please revert.
I know it's an IntelliJ warning but why should we tell Java to create an array generically by reflection when we literally know the size beforehand?

@@ -66,7 +66,7 @@ public void resetCount(String address, String name) {
if (isEnabled) {
TimedCounter<String> counter = ipLoginFailureCounts.get(address);
if (counter != null) {
counter.remove(name);
counter.remove(name.toLowerCase());
Copy link
Member

Choose a reason for hiding this comment

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

Great catch!

@@ -20,7 +20,7 @@
* @param auth the player auth object to save
*/
public void updatePlayer(PlayerAuth auth) {
cache.put(auth.getNickname().toLowerCase(), auth);
cache.put(auth.getNickname(), auth);
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure about this one? Aha, nickname is lowercase by definition. OK.

if (savedCode != null && savedCode.equalsIgnoreCase(code)) {
captchaCodes.remove(nameLowerCase);
captchaCodes.remove(name);
Copy link
Member

Choose a reason for hiding this comment

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

I think this one needs to be lowercase.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch

boolean result = source.removeAuth(name);
if (result) {
cachedAuths.invalidate(name);
cachedAuths.invalidate(name.toLowerCase());
}
return result;
Copy link
Member

Choose a reason for hiding this comment

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

Excellent!

}
} else {
if (sender != null) {
commonService.send(sender, MessageKey.ERROR);
}
ConsoleLogger.warning("An error occurred while changing password for user " + lowerCaseName + "!");
ConsoleLogger.warning("An error occurred while changing password for user " + playerName + "!");
Copy link
Member

Choose a reason for hiding this comment

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

This is a nice cleanup in this class. Thanks

final String ip = PlayerUtils.getPlayerIp(player);

if (service.getProperty(RestrictionSettings.UNRESTRICTED_NAMES).contains(name)) {
if (validationService.isUnrestricted(name)) {
Copy link
Member

Choose a reason for hiding this comment

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

👍

@@ -90,7 +90,7 @@ public void run() {
//we went through all offlineplayers but there are still names remaining
for (String name : toPurge) {
if (!permissionsManager.hasPermissionOffline(name, PlayerStatePermission.BYPASS_PURGE)) {
namePortion.add(name);
namePortion.add(name.toLowerCase());
Copy link
Member

@ljacqu ljacqu Dec 8, 2018

Choose a reason for hiding this comment

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

Good. Code later on requires namePortion being lowercase-only.

PlayerAuth auth = PlayerAuth.builder()
.name(playerNameLowerCase)
.name(playerName)
.realName(playerName)
Copy link
Member

@ljacqu ljacqu Dec 8, 2018

Choose a reason for hiding this comment

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

     .name(playerName)
     .realName(playerName)

This has bit of a funny feel now. It's absolutely 100% correct. I'm just wondering if it'd make sense to have a single name(String) function, since obviously from the realname we immediately know the all-lowercase name? This is maybe something we can look at after this pull request (for the sake of merging this soon). I expect that in some cases we do only want to set the name only (without a realname), but in most cases it would be nice if we just had to pass the name once and could tell the PlayerAuth builder "hey you, do what you need to do" 😄

Edit: So to be clear, my suggestion is to do nothing about it for now but we should keep it in the back of our heads.

Copy link
Member Author

Choose a reason for hiding this comment

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

yeah, we can enhance it in a future cleanup

@sgdc3
Copy link
Member Author

sgdc3 commented Dec 9, 2018

Now the problem is updating the unit test xD

@Xephi Xephi changed the title Lowercase cleanup [WIP] WIP - Lowercase cleanup Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants