Advertisement
Guest User

Untitled

a guest
Oct 2nd, 2017
135
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.42 KB | None | 0 0
  1. void NetworkThread::startInputLoop()
  2. {
  3.     int pingCount = 0;
  4.     while(!isInterruptionRequested()) {
  5.         if( !waitForReadyRead(1000) ) {
  6.             qInfo() << "Read timed out...\n";
  7.             break;
  8.         }
  9.  
  10.         QString message = readString(true);
  11.  
  12.         bool zoomEvent = false;
  13.         qint64 lastZoomEvent = 0;
  14.  
  15.         if(message == "PING") {
  16.             if( memcmp(getPassword().data(), getSessionHash().data(), 16) != 0)
  17.                 break;
  18.             qInfo() << "Pinging... " << ++pingCount << "\n";
  19.             writeString("PING", true);
  20.  
  21.             if(QDateTime::currentMSecsSinceEpoch() - lastZoomEvent < 1000)
  22.                 continue;
  23.         }
  24.  
  25.         if(message.startsWith("MouseMove ")) {
  26.             message.remove("MouseMove ");
  27.             QStringList coords = message.split(",");
  28.             int x = ((QString)coords.at(0)).toInt();
  29.             int y = ((QString)coords.at(1)).toInt();
  30.             FakeInput::mouseMove(x,y);
  31.         }
  32.         else if(message.startsWith("MouseSetPos ")) {
  33.             message.remove("MouseSetPos ");
  34.             QStringList coords = message.split(",");
  35.             int x = ((QString)coords.at(0)).toInt();
  36.             int y = ((QString)coords.at(1)).toInt();
  37.             FakeInput::mouseSetPos(x,y);
  38.         } else if(message.startsWith("MouseScroll ")) {
  39.             message.remove("MouseScroll ");
  40.             FakeInput::mouseScroll( message.toInt() );
  41.         } else if(message.startsWith("MouseDown ")) {
  42.             message.remove("MouseDown ");
  43.             FakeInput::mouseDown( message.toInt() );
  44.         } else if(message.startsWith("MouseUp ")) {
  45.             message.remove("MouseUp ");
  46.             FakeInput::mouseUp( message.toInt() );
  47.         } else if(message.startsWith("Backspace ")) {
  48.             message.remove("Backspace");
  49.             int n = abs( message.toInt() );
  50.             while(n-- > 0)
  51.                 FakeInput::keyTap("BackSpace");
  52.         } else if(message.startsWith("TypeString ")) {
  53.             message.remove(0, QString("TypeString ").length());
  54.             FakeInput::typeString(message);
  55.         } else if(message.startsWith("SpecialKey ")) {
  56.             message.remove("SpecialKey ");
  57.             if(message.startsWith("Down "))
  58.                 FakeInput::keyDown(message.remove("Down "));
  59.             else if(message.startsWith("Up "))
  60.                 FakeInput::keyUp(message.remove("Up "));
  61.             else
  62.                 FakeInput::keyTap(message.remove("Tap "));
  63.         } else if(message.startsWith("SpecialKeyCombo ")) {
  64.             message.remove("SpecialKeyCombo ");
  65.             specialKeyCombo(message);
  66.         } else if(message.startsWith("Zoom ")) {
  67.             zoomEvent = true;
  68.             lastZoomEvent = QDateTime::currentMSecsSinceEpoch();
  69.             message.remove("Zoom ");
  70.             FakeInput::zoom(message.toInt());
  71.         } else if(message.startsWith("Power ")) {
  72.             message.remove("Power ");
  73.             if(message == "Shutdown")
  74.                 FakeInput::shutdown();
  75.             else if(message == "Restart")
  76.                 FakeInput::restart();
  77.             else if(message == "Sleep")
  78.                 FakeInput::sleep();
  79.             else if(message == "Logout")
  80.                 FakeInput::logout();
  81.             else if(message == "Blank")
  82.                 FakeInput::blank_screen();
  83.             else if(message == "Lock")
  84.                 FakeInput::lock_screen();
  85.         } else if(message.startsWith("FileManager ")) {
  86.             message = message.remove(0, QString("FileManager ").length());
  87.             FileUtils::fileManagerCommand(message);
  88.         } else if(message.startsWith("ScreenMirror ")) {
  89.             message = message.remove("ScreenMirror ");
  90.             FileUtils::sendScreenJPG( message );
  91.         } else if(message.startsWith("Command ")) {
  92.             message = message.remove(0, QString("Command ").length());
  93.             if(message.startsWith("Run ")) {
  94.                 message = message.remove(0, QString("Run ").length());
  95.                 QString result = FakeInput::runCommandForResult(message);
  96.                 writeString(result, true);
  97.             }
  98.             else if(message.startsWith("Suggest ")) {
  99.                 message = message.remove(0, QString("Suggest ").length());
  100.                 QString suggestions = FakeInput::getCommandSuggestions(message);
  101.                 writeString(suggestions, true);
  102.             }
  103.         }
  104.         else if(message == "GetApplications") {
  105.             writeString(FakeInput::getApplicationNames(), true);
  106.         }
  107.         else if(message.startsWith("StartApplication ")) {
  108.             message = message.remove(0, QString("StartApplication ").length());
  109.             FakeInput::startApplicationByName(message);
  110.         }
  111.         else if(message == "GetCpuUsage") {
  112.             writeString(FakeInput::getCpuUsage(), true);
  113.         }
  114.         else if(message == "GetRamUsage") {
  115.             writeString(FakeInput::getRamUsage(), true);
  116.         }
  117.         else if(message == "GetTasks") {
  118.             writeString(FakeInput::getProcesses(), true);
  119.         }
  120.         else if(message.startsWith("KillPID")) {
  121.             message = message.remove("KillPID");
  122.             qInfo() << "Killing PID" << message;
  123.             FakeInput::killProcess(message);
  124.         }
  125.         else if(message == "Quit")
  126.             break;
  127.  
  128.         if(!zoomEvent)
  129.             FakeInput::stopZoom();
  130.     }
  131.     FakeInput::stopZoom();
  132. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement