Skip to content

Commit b097269

Browse files
authored
Fix: Clean player names of unwanted chars (#1008) (#1009)
* Fix: Clean player names of unwanted chars (#1008) * Fix: Dashboard player name
1 parent 9ed8db1 commit b097269

File tree

4 files changed

+53
-8
lines changed

4 files changed

+53
-8
lines changed

web/configs/version.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
22
"version": "1.8.0",
3-
"git": "1427",
3+
"git": "1428",
44
"dev": true
55
}

web/pages/page.banlist.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,17 @@ function setPostKey()
508508
}
509509

510510
$data['ban_date'] = Config::time($res->fields['ban_created']);
511-
$data['player'] = addslashes($res->fields['player_name']);
511+
512+
// Fix #1008 - bug: Player Names Contain Unwanted Non-Standard Characters
513+
$raw_name = $res->fields['player_name'];
514+
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
515+
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
516+
foreach ($unwanted_sequences as $sequence) {
517+
$cleaned_name = str_replace($sequence, '', $cleaned_name);
518+
}
519+
$cleaned_name = trim($cleaned_name);
520+
521+
$data['player'] = addslashes($cleaned_name);
512522
$data['type'] = $res->fields['type'];
513523
$data['steamid'] = $res->fields['authid'];
514524
// Fix #900 - Bad SteamID Format broke the page view, so give them an null SteamID.

web/pages/page.commslist.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,17 @@ function setPostKey()
481481
}
482482

483483
$data['ban_date'] = Config::time($res->fields['ban_created']);
484-
$data['player'] = addslashes($res->fields['player_name']);
484+
485+
// Fix #1008 - bug: Player Names Contain Unwanted Non-Standard Characters
486+
$raw_name = $res->fields['player_name'];
487+
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
488+
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
489+
foreach ($unwanted_sequences as $sequence) {
490+
$cleaned_name = str_replace($sequence, '', $cleaned_name);
491+
}
492+
$cleaned_name = trim($cleaned_name);
493+
494+
$data['player'] = addslashes($cleaned_name);
485495
$data['steamid'] = $res->fields['authid'];
486496
// Fix #906 - Bad SteamID Format broke the page view, so give them an null SteamID.
487497
if (!\SteamID\SteamID::isValidID($data['steamid'])) {

web/pages/page.home.php

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,14 @@
3838
while (!$res->EOF) {
3939
$info = [];
4040
$info['date'] = Config::time($res->fields[1]);
41-
$info['name'] = stripslashes(filter_var($res->fields[0], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES));
41+
$raw_name = stripslashes(filter_var($res->fields[0], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES));
42+
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
43+
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
44+
foreach ($unwanted_sequences as $sequence) {
45+
$cleaned_name = str_replace($sequence, '', $cleaned_name);
46+
}
47+
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
48+
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
4249
$info['short_name'] = trunc($info['name'], 40);
4350
$info['auth'] = $res->fields['authid'];
4451
$info['ip'] = $res->fields['ip'];
@@ -53,8 +60,12 @@
5360
$info['search_link'] = "index.php?p=banlist&advSearch=" . $info['auth'] . "&advType=steamid&Submit";
5461
}
5562
$info['link_url'] = "window.location = '" . $info['search_link'] . "';";
56-
$info['name'] = htmlspecialchars(addslashes($info['name']), ENT_QUOTES, 'UTF-8');
57-
$info['popup'] = "ShowBox('Blocked player: " . $info['name'] . "', '" . $info['name'] . " tried to enter<br />' + document.getElementById('" . $info['server'] . "').title + '<br />at " . $info['date'] . "<br /><div align=middle><a href=" . $info['search_link'] . ">Click here for ban details.</a></div>', 'red', '', true);";
63+
64+
// To print a name in the popup instead an empty string
65+
if (empty($cleaned_name)) {
66+
$cleaned_name = "<i>No nickname present</i>";
67+
}
68+
$info['popup'] = "ShowBox('Blocked player: " . $info['name'] . "', '" . $cleaned_name . " tried to enter<br />' + document.getElementById('" . $info['server'] . "').title + '<br />at " . $info['date'] . "<br /><div align=middle><a href=" . $info['search_link'] . ">Click here for ban details.</a></div>', 'red', '', true);";
5869

5970
$GLOBALS['server_qry'] .= "xajax_ServerHostProperty(" . $res->fields['sid'] . ", 'block_" . $res->fields['sid'] . "_$blcount', 'title', 100);";
6071

@@ -85,7 +96,14 @@
8596
$info['temp'] = true;
8697
$info['unbanned'] = false;
8798
}
88-
$info['name'] = stripslashes($res->fields[3]);
99+
$raw_name = stripslashes($res->fields[3]);
100+
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
101+
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
102+
foreach ($unwanted_sequences as $sequence) {
103+
$cleaned_name = str_replace($sequence, '', $cleaned_name);
104+
}
105+
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
106+
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
89107
$info['created'] = Config::time($res->fields['created']);
90108
$ltemp = explode(",", $res->fields[6] == 0 ? 'Permanent' : SecondsToString(intval($res->fields[6])));
91109
$info['length'] = $ltemp[0];
@@ -144,7 +162,14 @@
144162
$info['temp'] = true;
145163
$info['unbanned'] = false;
146164
}
147-
$info['name'] = stripslashes($res->fields[3]);
165+
$raw_name = stripslashes($res->fields[3]);
166+
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
167+
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
168+
foreach ($unwanted_sequences as $sequence) {
169+
$cleaned_name = str_replace($sequence, '', $cleaned_name);
170+
}
171+
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
172+
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
148173
$info['created'] = Config::time($res->fields['created']);
149174
$ltemp = explode(",", $res->fields[6] == 0 ? 'Permanent' : SecondsToString(intval($res->fields[6])));
150175
$info['length'] = $ltemp[0];

0 commit comments

Comments
 (0)