H-a-y-K

Untitled

Mar 15th, 2020
86
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #pragma once
  2.  
  3. #include <QtCore>
  4. #include <QtWebSockets>
  5. #include <QtNetwork>
  6.  
  7. class Player
  8. {
  9. public:
  10.     Player() = default;
  11.     Player(const QString&, QWebSocket*);
  12.  
  13.     bool operator==(const Player&) const;
  14.  
  15.     QString getName() const { return m_name; }
  16.     QWebSocket* getWSocket() const { return m_wsocket; }
  17.  
  18. private:
  19.     QWebSocket *m_wsocket;
  20.     QString m_name;
  21. };
  22.  
  23. typedef QPair<Player, Player> PlayerPair;
  24.  
  25. class Game
  26. {
  27. public:
  28.     Game() = default;
  29.     Game(const PlayerPair&);
  30.  
  31.     bool operator==(const Game&) const;
  32.  
  33.     QString getName() const { return m_name; }
  34.     PlayerPair getPlayers() { return m_players; }
  35.     Player getWhite() { return m_players.first; }
  36.     Player getBlack() { return m_players.second; }
  37.  
  38. private:
  39.     QString m_name;
  40.     PlayerPair m_players;
  41. };
  42.  
  43. class HichessServer : public QObject
  44. {
  45.     Q_OBJECT
  46.  
  47. public:
  48.     explicit HichessServer(QObject *parent = nullptr);
  49.  
  50. private slots:
  51.     void processPendingDatagrams();
  52.     void onNewConnection();
  53.     void onTextMessageReceived();
  54.  
  55. private:
  56.     QUdpSocket *m_udpServer;
  57.     QWebSocketServer *m_webServer;
  58.     QQueue<QString> m_usernameQueue;
  59.     QQueue<Player> m_playerQueue;
  60.     QLinkedList<Player> m_allPlayers;
  61.     QLinkedList<Game> m_games;
  62.  
  63.     void manageConnections();
  64.     void addClient(QWebSocket*);
  65.     void removeClient(QWebSocket*);
  66. };
RAW Paste Data