Skip to content

Commit 1813cb4

Browse files
committed
Fix server console history not working right with utf
1 parent eba619d commit 1813cb4

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

Server/core/CServerImpl.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -794,14 +794,16 @@ void CServerImpl::HandleInput()
794794
}
795795
else
796796
{
797-
SString szCommand = UTF16ToMbUTF8(m_szInputBuffer).c_str();
798797
// Otherwise, pass the command to the mod's input handler
799-
m_pModManager->HandleInput(szCommand);
798+
m_pModManager->HandleInput(UTF16ToMbUTF8(m_szInputBuffer).c_str());
800799

801800
// If the command is not empty and it isn't identical to the previous entry in history, add it to the history
802801
// The first string is the original command, the second string is for storing the edited command
803-
if (!szCommand.empty() && (m_vecCommandHistory.empty() || m_vecCommandHistory.back()[0] != szCommand))
804-
m_vecCommandHistory.push_back({szCommand, szCommand});
802+
if (const std::wstring wzCommand = m_szInputBuffer;
803+
!wzCommand.empty() && (m_vecCommandHistory.empty() || m_vecCommandHistory.back()[0] != wzCommand))
804+
{
805+
m_vecCommandHistory.push_back({wzCommand, wzCommand});
806+
}
805807
}
806808
}
807809

@@ -962,20 +964,20 @@ void CServerImpl::SelectCommandHistoryEntry(uint uiEntry)
962964
m_uiSelectedCommandHistoryEntry = 0;
963965

964966
// Save current input buffer to the command history entry as the second element
965-
m_vecCommandHistory[uiPreviouslySelectedCommandHistoryEntry][1] = UTF16ToMbUTF8(m_szInputBuffer).c_str();
967+
m_vecCommandHistory[uiPreviouslySelectedCommandHistoryEntry][1] = std::wstring(m_szInputBuffer);
966968

967969
// Clear input
968970
ClearInput();
969971

970972
// If the selected command is empty, let's just stop here
971-
SString szInput = m_vecCommandHistory[m_uiSelectedCommandHistoryEntry][1];
972-
if (szInput.empty())
973+
const auto wzInput = m_vecCommandHistory[m_uiSelectedCommandHistoryEntry][1];
974+
if (wzInput.empty())
973975
return;
974976

975977
// Fill the input buffer
976-
m_uiInputCount = szInput.length();
977-
for (uint i = 0; i < szInput.length(); i++)
978-
m_szInputBuffer[i] = szInput[i];
978+
m_uiInputCount = wzInput.length();
979+
for (uint i = 0; i < wzInput.length(); i++)
980+
m_szInputBuffer[i] = wzInput[i];
979981

980982
// Let's print it out
981983
wchar_t szBuffer[255] = {};

Server/core/CServerImpl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ class CServerImpl : public CServerInterface
109109

110110
int m_exitCode;
111111

112-
std::vector<std::vector<SString>> m_vecCommandHistory = {{"", ""}};
113-
uint m_uiSelectedCommandHistoryEntry = 0;
112+
std::vector<std::vector<std::wstring>> m_vecCommandHistory = {{L"", L""}};
113+
uint m_uiSelectedCommandHistoryEntry = 0;
114114

115115
#ifdef WIN32
116116
HANDLE m_hConsole;

0 commit comments

Comments
 (0)