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 locale switch for names with non-ascii characters #945

Merged
merged 1 commit into from
Jul 28, 2024
Merged
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
8 changes: 4 additions & 4 deletions Server/Source/core_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1778,18 +1778,18 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
#ifdef BUILD_WINDOWS
_lock_locales();
UINT oldCP = 0;
char oldLocale[64] = { 0 };
wchar_t oldLocale[64] = { 0 };
bool oldLocaleSaved = false;
if (utf8)
{
oldCP = GetConsoleOutputCP();
SetConsoleOutputCP(CP_UTF8);

/* Getting current locale */
const char* old_locale_ptr = std::setlocale(LC_CTYPE, nullptr);
const wchar_t* old_locale_ptr = _wsetlocale(LC_CTYPE, nullptr);
if (old_locale_ptr != nullptr)
{
strcpy_s(oldLocale, old_locale_ptr);
wcscpy_s(oldLocale, old_locale_ptr);
oldLocaleSaved = true;

std::setlocale(LC_CTYPE, ".UTF-8");
Expand Down Expand Up @@ -1867,7 +1867,7 @@ class Core final : public ICore, public PlayerConnectEventHandler, public Consol
{
if (oldLocaleSaved)
{
std::setlocale(LC_CTYPE, oldLocale);
_wsetlocale(LC_CTYPE, oldLocale);
}
SetConsoleOutputCP(oldCP);
}
Expand Down
Loading