MCPcopy Create free account
hub / github.com/deathkiller/jazz2-native / StartProcessingStdin

Method StartProcessingStdin

Sources/Main.cpp:888–935  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

886}
887
888void 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)

Callers

nothing calls this directly

Calls 11

DEATH_ASSERTFunction · 0.85
SendMessageToAllMethod · 0.80
arraySizeFunction · 0.50
FromUtf16Function · 0.50
arrayViewFunction · 0.50
trimmedMethod · 0.45
emptyMethod · 0.45
DisposeMethod · 0.45
QuitMethod · 0.45
ProcessCommandMethod · 0.45
hasPrefixMethod · 0.45

Tested by

no test coverage detected