Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void NetworkThread::startInputLoop()
- {
- int pingCount = 0;
- while(!isInterruptionRequested()) {
- if( !waitForReadyRead(1000) ) {
- qInfo() << "Read timed out...\n";
- break;
- }
- QString message = readString(true);
- bool zoomEvent = false;
- qint64 lastZoomEvent = 0;
- if(message == "PING") {
- if( memcmp(getPassword().data(), getSessionHash().data(), 16) != 0)
- break;
- qInfo() << "Pinging... " << ++pingCount << "\n";
- writeString("PING", true);
- if(QDateTime::currentMSecsSinceEpoch() - lastZoomEvent < 1000)
- continue;
- }
- if(message.startsWith("MouseMove ")) {
- message.remove("MouseMove ");
- QStringList coords = message.split(",");
- int x = ((QString)coords.at(0)).toInt();
- int y = ((QString)coords.at(1)).toInt();
- FakeInput::mouseMove(x,y);
- }
- else if(message.startsWith("MouseSetPos ")) {
- message.remove("MouseSetPos ");
- QStringList coords = message.split(",");
- int x = ((QString)coords.at(0)).toInt();
- int y = ((QString)coords.at(1)).toInt();
- FakeInput::mouseSetPos(x,y);
- } else if(message.startsWith("MouseScroll ")) {
- message.remove("MouseScroll ");
- FakeInput::mouseScroll( message.toInt() );
- } else if(message.startsWith("MouseDown ")) {
- message.remove("MouseDown ");
- FakeInput::mouseDown( message.toInt() );
- } else if(message.startsWith("MouseUp ")) {
- message.remove("MouseUp ");
- FakeInput::mouseUp( message.toInt() );
- } else if(message.startsWith("Backspace ")) {
- message.remove("Backspace");
- int n = abs( message.toInt() );
- while(n-- > 0)
- FakeInput::keyTap("BackSpace");
- } else if(message.startsWith("TypeString ")) {
- message.remove(0, QString("TypeString ").length());
- FakeInput::typeString(message);
- } else if(message.startsWith("SpecialKey ")) {
- message.remove("SpecialKey ");
- if(message.startsWith("Down "))
- FakeInput::keyDown(message.remove("Down "));
- else if(message.startsWith("Up "))
- FakeInput::keyUp(message.remove("Up "));
- else
- FakeInput::keyTap(message.remove("Tap "));
- } else if(message.startsWith("SpecialKeyCombo ")) {
- message.remove("SpecialKeyCombo ");
- specialKeyCombo(message);
- } else if(message.startsWith("Zoom ")) {
- zoomEvent = true;
- lastZoomEvent = QDateTime::currentMSecsSinceEpoch();
- message.remove("Zoom ");
- FakeInput::zoom(message.toInt());
- } else if(message.startsWith("Power ")) {
- message.remove("Power ");
- if(message == "Shutdown")
- FakeInput::shutdown();
- else if(message == "Restart")
- FakeInput::restart();
- else if(message == "Sleep")
- FakeInput::sleep();
- else if(message == "Logout")
- FakeInput::logout();
- else if(message == "Blank")
- FakeInput::blank_screen();
- else if(message == "Lock")
- FakeInput::lock_screen();
- } else if(message.startsWith("FileManager ")) {
- message = message.remove(0, QString("FileManager ").length());
- FileUtils::fileManagerCommand(message);
- } else if(message.startsWith("ScreenMirror ")) {
- message = message.remove("ScreenMirror ");
- FileUtils::sendScreenJPG( message );
- } else if(message.startsWith("Command ")) {
- message = message.remove(0, QString("Command ").length());
- if(message.startsWith("Run ")) {
- message = message.remove(0, QString("Run ").length());
- QString result = FakeInput::runCommandForResult(message);
- writeString(result, true);
- }
- else if(message.startsWith("Suggest ")) {
- message = message.remove(0, QString("Suggest ").length());
- QString suggestions = FakeInput::getCommandSuggestions(message);
- writeString(suggestions, true);
- }
- }
- else if(message == "GetApplications") {
- writeString(FakeInput::getApplicationNames(), true);
- }
- else if(message.startsWith("StartApplication ")) {
- message = message.remove(0, QString("StartApplication ").length());
- FakeInput::startApplicationByName(message);
- }
- else if(message == "GetCpuUsage") {
- writeString(FakeInput::getCpuUsage(), true);
- }
- else if(message == "GetRamUsage") {
- writeString(FakeInput::getRamUsage(), true);
- }
- else if(message == "GetTasks") {
- writeString(FakeInput::getProcesses(), true);
- }
- else if(message.startsWith("KillPID")) {
- message = message.remove("KillPID");
- qInfo() << "Killing PID" << message;
- FakeInput::killProcess(message);
- }
- else if(message == "Quit")
- break;
- if(!zoomEvent)
- FakeInput::stopZoom();
- }
- FakeInput::stopZoom();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement