InputSocket.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. //
  2. // Created by Tobias Hieta on 24/08/15.
  3. //
  4. #include <QDebug>
  5. #include "InputSocket.h"
  6. #include "Version.h"
  7. #include <QDataStream>
  8. /////////////////////////////////////////////////////////////////////////////////////////
  9. bool InputSocket::initInput()
  10. {
  11. return m_server->listen();
  12. }
  13. /////////////////////////////////////////////////////////////////////////////////////////
  14. void InputSocket::clientConnected(QLocalSocket* socket)
  15. {
  16. QVariantMap welcome;
  17. welcome.insert("version", Version::GetVersionString());
  18. welcome.insert("builddate", Version::GetBuildDate());
  19. m_server->sendMessage(welcome, socket);
  20. }
  21. /////////////////////////////////////////////////////////////////////////////////////////
  22. void InputSocket::messageReceived(const QVariant& message)
  23. {
  24. QVariantMap map = message.toMap();
  25. if (!map.contains("client") || !map.contains("source") || !map.contains("keycode"))
  26. {
  27. qWarning() << "Got packet from client but it was missing the important fields";
  28. return;
  29. }
  30. qDebug() << "Input from client:" << map.value("client").toString() << " - " <<
  31. map.value("source").toString() << map.value("keycode").toString();
  32. emit receivedInput(map.value("source").toString(), map.value("keycode").toString(), KeyPressed);
  33. }