Skip to content

Emoji Ban Fix 1#506

Closed
Ruok2bu wants to merge 1 commit intosbpp:v1.xfrom
Ruok2bu:patch-1
Closed

Emoji Ban Fix 1#506
Ruok2bu wants to merge 1 commit intosbpp:v1.xfrom
Ruok2bu:patch-1

Conversation

@Ruok2bu
Copy link

@Ruok2bu Ruok2bu commented Aug 26, 2018

This fix changes the character set of the database so that players with Emoji's in their name can be banned. Since the source engine can't parse Emoji's, the value for the player's emoji is random text in the sourcebans database.

Description

Replaces all instances of utf8 with utf8mb4

Motivation and Context

Players with emoji in name could not be banned (because default character set configured by installer does not take into account the 4 bytes needed for emoji).

How Has This Been Tested?

I installed the plugin change on 10 servers.

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.

This fix changes the character set of the database so that players with Emoji's in their name can be banned. Since the source engine can't parse Emoji's, the value for the player's emoji is random text in the sourcebans database.

Sourcemod installer needs to be updated to use the following for database setup:
Character Set: utf8mb4
Collation: utf8mb4_unicode_ci
@CrazyHackGUT
Copy link
Contributor

You can just remove emojis from nickname before inserting to query.
This function written by @komashchenko

char[] GetFixNamePlayer(int iClient)
{
    char sName[MAX_NAME_LENGTH * 2 + 1];
    GetClientName(iClient, sName, sizeof(sName));

    for(int i = 0, len = strlen(sName), CharBytes; i < len;)
    {
        if((CharBytes = GetCharBytes(sName[i])) == 4)
        {
            len -= 4;
            for(int u = i; u <= len; u++)
            {
                sName[u] = sName[u+4];
            }
        }
        else i += CharBytes;
    }
    return sName;
}

@Bara
Copy link

Bara commented Aug 27, 2018

utf8mb4 charset would require sourcemod 1.10 with updated mysql version.
I recommend to include your 2nd PR here.

@rumblefrog
Copy link
Member

Is there a reason to have 2 PRs?

@Ruok2bu
Copy link
Author

Ruok2bu commented Aug 28, 2018

It's the first time i ever did a PR on Github. I thought a PR was needed for each edit (since different files are edited). @CrazyHackGUT I wish i'd known about that weeks ago when i asked for help in the sbpp discord server. No one had any (working) solutions (including Fishy!) for the emoji issue.

@CrazyHackGUT One potential problem with that code is if the user's name is all emoji.

@rumblefrog
Copy link
Member

rumblefrog commented Aug 28, 2018 via email

@CrazyHackGUT
Copy link
Contributor

@Ruok2bu it's simple to resolve.
After receiving nickname from this function, you call TrimString(). This function removes all spaces before and after nickname.
And just check, empty string or not:

if (szUsername[0] == 0) // nickname is empty
  strcopy(szUsername, sizeof(szUsername), "unnamed"); // copy to username string "unnamed"

@Groruk Groruk mentioned this pull request Nov 23, 2018
7 tasks
@Groruk Groruk closed this in #536 Nov 23, 2018
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.

4 participants