Hi there,
I'm using LevelsRanks plugin on my CS:GO server and I'm facing weird strings in my database caused by the Database.Escape() function.
My ingame name is "
No'". When I use the Database.Escape() function onto it, the output is "
No\'" which is ok.
But A guy came with this name : "
Everything's gonna be alright" and the Database.Escape() output was "
Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\ \\\". Which is really weird.
Somes other guys have this issue and it seems to appen when you have a quote in your name, everythings behind it is replaced with backslashs and quote (the pattern seems random aswell).
Anyone got this error ? Seems to be a Sourcemod bug. I'm using SM 1.10.0 6488 (the latest) and used 6482 before (both have the issue). I'm here because I can't find anything on the forum and on github, am I the first guy to get this error ? Or its just a scripting issue ?
So here's a little script I wrote to test the escape function (I used the levels_ranks database config but you can use anything you want to test, for me its a mysql database). This script uses the levels_ranks buffers size.
PHP Code:
#include <sourcemod>
public Plugin myinfo =
{
name = "Database.Escape test",
author = "Nobody-x",
version = "1"
};
Database g_hDatabase;
public void OnPluginStart() {
Database.Connect(OnDBConnect, "levels_ranks");
RegConsoleCmd("sm_test", Cmd_Test)
RegConsoleCmd("sm_test2", Cmd_Test2)
}
Action Cmd_Test(int client, int args) {
if (g_hDatabase == null) {
return Plugin_Continue;
}
char sName[65];
GetClientName(client, sName, 32);
LogMessage("Client name : \"%s\"", sName);
g_hDatabase.Escape(sName, sName, sizeof(sName));
LogMessage("Escaped name : \"%s\"", sName);
return Plugin_Changed;
}
Action Cmd_Test2(int client, int args) {
if (g_hDatabase == null) {
return Plugin_Continue;
}
char sName[65];
GetClientName(client, sName, 32);
LogMessage("Client name : \"%s\"", sName);
SQL_EscapeString(g_hDatabase, sName, sName, sizeof(sName));
LogMessage("Escaped name : \"%s\"", sName);
return Plugin_Changed;
}
public void OnDBConnect(Database db, const char[] error, any data)
{
if (db == null)
{
LogError("Database failure: %s", error);
return;
}
g_hDatabase = db;
}
Edit:
These are the outputs of both commands :
Code:
L 05/05/2020 - 22:04:30: [test_escape.smx] Client name : "Everything's gonna be alright"
L 05/05/2020 - 22:04:30: [test_escape.smx] Escaped name : "Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\\\\"
L 05/05/2020 - 22:04:32: [test_escape.smx] Client name : "Everything's gonna be alright"
L 05/05/2020 - 22:04:32: [test_escape.smx] Escaped name : "Everything\'\'\\\'\\\\\\\'\\\\\\\\\\\\\\\'\\\\\\"
L 05/05/2020 - 22:04:08: [test_escape.smx] Client name : "No'"
L 05/05/2020 - 22:04:08: [test_escape.smx] Escaped name : "No\'"
L 05/05/2020 - 22:04:11: [test_escape.smx] Client name : "No'"
L 05/05/2020 - 22:04:11: [test_escape.smx] Escaped name : "No\'"