MCPcopy Create free account
hub / github.com/axmolengine/axmol / parseCommand

Method parseCommand

core/base/Console.cpp:716–777  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

714}
715
716bool Console::parseCommand(socket_native_type fd)
717{
718 char buf[512];
719 bool more_data;
720 auto h = readBytes(fd, buf, 6, &more_data);
721 if (h < 0)
722 {
723 return false;
724 }
725 if (strncmp(buf, "upload", 6) == 0)
726 {
727 char c = '\0';
728 recv(fd, &c, 1, 0);
729 if (c == ' ')
730 {
731 commandUpload(fd);
732 Console::Utility::sendPrompt(fd);
733 return true;
734 }
735 else
736 {
737 const char err[] = "upload: invalid args! Type 'help' for options\n";
738 Console::Utility::sendToConsole(fd, err, strlen(err));
739 Console::Utility::sendPrompt(fd);
740 return true;
741 }
742 }
743 if (!more_data)
744 {
745 buf[h] = 0;
746 }
747 else
748 {
749 char* pb = buf + 6;
750 auto r = readline(fd, pb, sizeof(buf) - 6);
751 if (r < 0)
752 {
753 const char err[] = "Unknown error!\n";
754 Console::Utility::sendPrompt(fd);
755 Console::Utility::sendToConsole(fd, err, strlen(err));
756 return false;
757 }
758 }
759 std::string cmdLine;
760 cmdLine = std::string(buf);
761 auto commands = Console::Utility::split(cmdLine, _commandSeparator);
762 try
763 {
764 for (auto&& command : commands)
765 {
766 performCommand(fd, Console::Utility::trim(command));
767 }
768 }
769 catch (const std::runtime_error& e)
770 {
771 Console::Utility::sendToConsole(fd, e.what(), strlen(e.what()));
772 }
773

Callers

nothing calls this directly

Calls 3

readlineFunction · 0.85
splitFunction · 0.70
whatMethod · 0.45

Tested by

no test coverage detected