Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Clean player names of unwanted chars (#1008) #1009

Merged
merged 2 commits into from
Nov 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion web/configs/version.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "1.8.0",
"git": "1427",
"git": "1428",
"dev": true
}
12 changes: 11 additions & 1 deletion web/pages/page.banlist.php
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,17 @@ function setPostKey()
}

$data['ban_date'] = Config::time($res->fields['ban_created']);
$data['player'] = addslashes($res->fields['player_name']);

// Fix #1008 - bug: Player Names Contain Unwanted Non-Standard Characters
$raw_name = $res->fields['player_name'];
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
foreach ($unwanted_sequences as $sequence) {
$cleaned_name = str_replace($sequence, '', $cleaned_name);
}
$cleaned_name = trim($cleaned_name);

$data['player'] = addslashes($cleaned_name);
$data['type'] = $res->fields['type'];
$data['steamid'] = $res->fields['authid'];
// Fix #900 - Bad SteamID Format broke the page view, so give them an null SteamID.
Expand Down
12 changes: 11 additions & 1 deletion web/pages/page.commslist.php
Original file line number Diff line number Diff line change
Expand Up @@ -481,7 +481,17 @@ function setPostKey()
}

$data['ban_date'] = Config::time($res->fields['ban_created']);
$data['player'] = addslashes($res->fields['player_name']);

// Fix #1008 - bug: Player Names Contain Unwanted Non-Standard Characters
$raw_name = $res->fields['player_name'];
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
foreach ($unwanted_sequences as $sequence) {
$cleaned_name = str_replace($sequence, '', $cleaned_name);
}
$cleaned_name = trim($cleaned_name);

$data['player'] = addslashes($cleaned_name);
$data['steamid'] = $res->fields['authid'];
// Fix #906 - Bad SteamID Format broke the page view, so give them an null SteamID.
if (!\SteamID\SteamID::isValidID($data['steamid'])) {
Expand Down
35 changes: 30 additions & 5 deletions web/pages/page.home.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,14 @@
while (!$res->EOF) {
$info = [];
$info['date'] = Config::time($res->fields[1]);
$info['name'] = stripslashes(filter_var($res->fields[0], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES));
$raw_name = stripslashes(filter_var($res->fields[0], FILTER_SANITIZE_SPECIAL_CHARS, FILTER_FLAG_NO_ENCODE_QUOTES));
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
foreach ($unwanted_sequences as $sequence) {
$cleaned_name = str_replace($sequence, '', $cleaned_name);
}
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
$info['short_name'] = trunc($info['name'], 40);
$info['auth'] = $res->fields['authid'];
$info['ip'] = $res->fields['ip'];
Expand All @@ -53,8 +60,12 @@
$info['search_link'] = "index.php?p=banlist&advSearch=" . $info['auth'] . "&advType=steamid&Submit";
}
$info['link_url'] = "window.location = '" . $info['search_link'] . "';";
$info['name'] = htmlspecialchars(addslashes($info['name']), ENT_QUOTES, 'UTF-8');
$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);";

// To print a name in the popup instead an empty string
if (empty($cleaned_name)) {
$cleaned_name = "<i>No nickname present</i>";
}
$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);";

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

Expand Down Expand Up @@ -85,7 +96,14 @@
$info['temp'] = true;
$info['unbanned'] = false;
}
$info['name'] = stripslashes($res->fields[3]);
$raw_name = stripslashes($res->fields[3]);
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
foreach ($unwanted_sequences as $sequence) {
$cleaned_name = str_replace($sequence, '', $cleaned_name);
}
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
$info['created'] = Config::time($res->fields['created']);
$ltemp = explode(",", $res->fields[6] == 0 ? 'Permanent' : SecondsToString(intval($res->fields[6])));
$info['length'] = $ltemp[0];
Expand Down Expand Up @@ -144,7 +162,14 @@
$info['temp'] = true;
$info['unbanned'] = false;
}
$info['name'] = stripslashes($res->fields[3]);
$raw_name = stripslashes($res->fields[3]);
$cleaned_name = mb_convert_encoding($raw_name, 'UTF-8', 'UTF-8');
$unwanted_sequences = ["\xF3\xA0\x80\xA1"];
foreach ($unwanted_sequences as $sequence) {
$cleaned_name = str_replace($sequence, '', $cleaned_name);
}
$cleaned_name = str_replace($unwanted_sequence, '', $cleaned_name);
$info['name'] = htmlspecialchars(addslashes($cleaned_name), ENT_QUOTES, 'UTF-8');
$info['created'] = Config::time($res->fields['created']);
$ltemp = explode(",", $res->fields[6] == 0 ? 'Permanent' : SecondsToString(intval($res->fields[6])));
$info['length'] = $ltemp[0];
Expand Down