| 886 | } |
| 887 | |
| 888 | void GameEventHandler::StartProcessingStdin() |
| 889 | { |
| 890 | Thread thread([](void* arg) { |
| 891 | auto _this = static_cast<GameEventHandler*>(arg); |
| 892 | DEATH_ASSERT(_this != nullptr); |
| 893 | |
| 894 | # if defined(DEATH_TARGET_WINDOWS) |
| 895 | wchar_t bufferW[4096]; |
| 896 | HANDLE hStdIn = ::GetStdHandle(STD_INPUT_HANDLE); |
| 897 | # else |
| 898 | char buffer[4096]; |
| 899 | # endif |
| 900 | |
| 901 | while (true) { |
| 902 | # if defined(DEATH_TARGET_WINDOWS) |
| 903 | DWORD charsRead; |
| 904 | if (!::ReadConsoleW(hStdIn, bufferW, DWORD(arraySize(bufferW)), &charsRead, nullptr)) { |
| 905 | LOGW("Failed to read from stdin"); |
| 906 | break; |
| 907 | } |
| 908 | String buffer = Utf8::FromUtf16(arrayView(bufferW, charsRead)); |
| 909 | # else |
| 910 | if (!::fgets(buffer, sizeof(buffer), stdin)) { |
| 911 | LOGW("Failed to read from stdin"); |
| 912 | break; |
| 913 | } |
| 914 | # endif |
| 915 | |
| 916 | StringView line = buffer; |
| 917 | line = line.trimmed(); |
| 918 | |
| 919 | if (!line.empty()) { |
| 920 | if (line == "/exit"_s || line == "/quit"_s) { |
| 921 | if (_this->_networkManager != nullptr) { |
| 922 | _this->_networkManager->Dispose(); |
| 923 | _this->_networkManager = nullptr; |
| 924 | } |
| 925 | theApplication().Quit(); |
| 926 | break; |
| 927 | } else if (auto levelHandler = runtime_cast<MpLevelHandler>(_this->_currentHandler)) { |
| 928 | if (!levelHandler->ProcessCommand({}, line, true) && !line.hasPrefix('/')) { |
| 929 | levelHandler->SendMessageToAll(line, true); |
| 930 | } |
| 931 | } |
| 932 | } |
| 933 | } |
| 934 | }, this); |
| 935 | } |
| 936 | #endif |
| 937 | |
| 938 | #if defined(WITH_MULTIPLAYER) |
nothing calls this directly
no test coverage detected