tomtko / Surftimer-archived

A CS:GO Surftimer which is heavily modified from ckSurf
GNU General Public License v3.0
53 stars 43 forks source link

Times not saving, charset issue #131

Open kmsraidboss opened 5 years ago

kmsraidboss commented 5 years ago

Similarly to Sourcebans (https://github.com/sbpp/sourcebans-pp/issues/567) and some others, Surftimer is having an issue where people who have names with certain characters in them are unable to have their times saved due to an error occurring when processing those names.

Here is the basic error that's happening to players with these characters in their name:

L 08/12/2019 - 17:55:18: [SurfTimer.smx] [Surftimer] SQL Error (SQL_InsertPlayerCallBack): Incorrect string value: '\xF0\x9F\x90\xB3 \xF0...' for column 'name' at row 1

I linked the Sourcebans issues thread above because it's talked about in there as well and apparently resolved in a recent version, but I'm not sure how. I just think that most people must be suffering from it so the plugin as a whole could use it addressed, it's sort of game breaking in a sense. For me, it's been going on for a while but only recently came to my attention, so it's likely some folks don't even know it's happening on their servers.

Bara commented 5 years ago

Default the database will created with utf8mb4 charset, but the issue is this part of code: https://github.com/fluffyst/Surftimer/blob/master/addons/sourcemod/scripting/surftimer/sql.sp#L43 the connection will be handled as utf8 instead of utf8mb4.

An solution could be this here:

if (!SQL_SetCharset(g_hDb, "utf8mb4"))
{
    SQL_SetCharset(g_hDb, "utf8");
}

maybe with an string for the charset like this:

char sCharset[16];

if (!SQL_SetCharset(g_hDb, "utf8mb4"))
{
    SQL_SetCharset(g_hDb, "utf8");
    Format(sCharset, sizeof(sCharset), "utf8");
}
else´
{
    Format(sCharset, sizeof(sCharset), "utf8mb4");
}

some adjustments in the query definied strings to replace "utf8mb4" with "utf8" if the utf8mb4 charset isn't supported (or SQL_SetCharset wasn't successful).

// Edit: And if you really want to fix this, sourcemod 1.10 is required for this.

kmsraidboss commented 5 years ago

I run 1.10 already. I'll give what you wrote above a try and see how it works.