Skip to content

Conversation

@Yur1Ca
Copy link
Contributor

@Yur1Ca Yur1Ca commented Oct 25, 2025

Problem Description:
This change addresses a critical character encoding issue in SourceBans++ that caused garbled text when storing Chinese player names in the database. The root cause was identified as:

  1. Character Set Timing Issue:
    The original code used asynchronous db.Query() to execute SET NAMES utf8mb4, which meant that plugin operations (like INSERT) could begin before the character set configuration was complete.

  2. Asynchronous Execution Risk:
    When players were banned, if the character set configuration hadn't finished, Chinese characters would be written to the database with incorrect encoding, resulting in garbled text.

Test Environment:

  • SourceMod 1.12
  • MySQL 8.0 database

Test Cases Executed:

  1. Chinese player name ban system test

    • Used players with Chinese names to trigger the ban system
    • Verified that Chinese characters are correctly stored in the database without garbled text
  2. Multi-byte character storage test

    • Tested storage of various character types:
      • Chinese characters
      • Japanese characters
      • Special characters and symbols
    • Confirmed all characters are properly encoded and displayed correctly

Test Results:

  • ✅ All Chinese, Japanese, and special characters are correctly stored in the database
  • ✅ No garbled text appears in player names
  • ✅ Character set configuration works synchronously before any database operations
  • ✅ Error logging functions properly for troubleshooting

Checklist:
✅My code follows the code style of this project.
✅I have read the CONTRIBUTING document.

Copy link
Member

@rumblefrog rumblefrog left a comment

Choose a reason for hiding this comment

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

I vaguely remember something funny with SetCharset in SM, but I hope that it works as intended now.

@rumblefrog rumblefrog merged commit 0500b86 into sbpp:php81 Nov 2, 2025
3 checks 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.

2 participants