PDA

View Full Version : [CoD2] [MySQL] [libcod] Special characters



BlancO
19th November 2013, 22:21
Hello,

I've got a problem with players' names on server. I want to store them in MySQL DB. Connection works nice. I save it without problems. But I can't read/select including special chatacters.

I have written debug to check, whats wrong.

Normally I got this:


guid=123456 score=0 name=Unnamed Player


But when player has special characters in his name:


^33×YankeS×^2Ž


PHP reads his name as:


^^00Gumowy#^2Š››^^33×YankeS×^2Ž


The real nickname is:
540

MySQL query:


SELECT `guid`, `score`, `last_nick` FROM players WHERE `guid`='xxxxxx'


How can I read special characters from MySQL?

IzNoGoD
20th November 2013, 06:49
Insert them using


newstring = mysql_real_escape_string(mysql, oldstring)

BlancO
20th November 2013, 19:16
I'm not quite sure if I am doing it right:



sql = "UPDATE players SET nick='" + mysql_real_escape_string(level.mysql, self.name) + "' WHERE guid='" + self getGuid() + "'";

kung foo man
20th November 2013, 19:54
Had same issues, dunno anymore what I did exactly to solve it though. Try something like:




$strQuery = "SET character_set_results = 'utf8',
character_set_client = 'utf8',
character_set_connection = 'utf8',
character_set_database = 'utf8',
character_set_server = 'utf8'";
mysql_query($strQuery);




while ($row = mysql_fetch_assoc($query))
{
$hostname = utf8_decode($row["hostname"]);

echo $hostname;
}

BlancO
20th November 2013, 20:25
How is it possible in .gsc files?

kung foo man
21st November 2013, 21:30
ATM there is no such function, but you could either add that function yourself or test first with getAscii() of libcod:



getAscii(str) { return closer(902, str); }


Example from ClientCommand:



fixChatArgs(args)
{
if (isDefined(args[1])) { // engine is adding identifier infront of the chat message
if (std\utils::getAscii(args[1][0]) >= 20 && std\utils::getAscii(args[1][0]) <= 22) {
//std\io::print("delete bad ascii code: " + std\utils::getAscii(args[1][0]) + "\n");
args[1] = getSubStr(args[1], 1);

newArgs = strTok(args[1], " ");
for (i=0; i<newArgs.size; i++)
args[1+i] = newArgs[i];
}
}
return args;
}


Then step over any char, print the ascii-numbers, check whats wrong, search for solution. :D