App.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #ifndef APP_H
  2. #define APP_H
  3. #include <QCoreApplication>
  4. #include <QList>
  5. #include <QSettings>
  6. #include <QHostAddress>
  7. #include <QTime>
  8. #include <QTimer>
  9. class SshClient;
  10. class QTcpSocket;
  11. class QTcpServer;
  12. class Client;
  13. class ServerQueryThread;
  14. class App : public QCoreApplication
  15. {
  16. Q_OBJECT
  17. public:
  18. explicit App(int &argc, char **argv);
  19. ~App();
  20. void print(const QString& msg);
  21. void broadcast(const QString& msg, int *serverCount, int *userCount);
  22. void broadcast(const QString& msg);
  23. void requestBroadcast(const QString& type, const QString& user, const QString& server, const QString& message);
  24. void setReplyHash(const QString& serverAddress, const QString& hash);
  25. void incrementReplyCounters(const QString& hash, int userCount, int serverCount);
  26. void activeClientsReplyCounters(int *serverCount, int *playerCount);
  27. protected:
  28. void timerEvent(QTimerEvent *e);
  29. private:
  30. class ActiveClient
  31. {
  32. public:
  33. ActiveClient(App* app);
  34. ~ActiveClient();
  35. Client* client();
  36. ServerQueryThread*queryThread();
  37. void run();
  38. void setAddress(const QHostAddress &address, quint16 port);
  39. const QString serverAddressString();
  40. void setReplyHash(const QString& hash); //this activates the 5 seconds reply timer too
  41. const QString& replyHash() const;
  42. void incrementReplyCounters(int userCount, int serverCount);
  43. bool isWaitingReply() const;
  44. private:
  45. App* myApp;
  46. Client* myClient;
  47. ServerQueryThread*myQueryThread;
  48. ActiveClient(const ActiveClient&) {}
  49. QTime myDisconnectTime;
  50. /* Count server reply while timer is active */
  51. QString myReplyHash;
  52. QTimer* myBroadcastReplyTimer;
  53. int myUniqueUserCount;
  54. int myUniqueServerCount;
  55. bool myReplyTimerWasActive;
  56. };
  57. QTcpSocket* mySocket;
  58. QTcpServer* myServer;
  59. bool mySocketConnectedFlag;
  60. SshClient* myQWNETSshClient;
  61. QList<ActiveClient*> myClients;
  62. quint32 myCurrentClient;
  63. QSettings mySettings;
  64. int myClientsFrameTimerID; //timer for mainloop
  65. void loadClients();
  66. void cleanup();
  67. /* TCP Server */
  68. bool checkPassword(const QString& password);
  69. void addClient(const QString& host, quint16 port);
  70. void removeClient(const QString& host, quint16 port);
  71. void connectToServer(const QString& args);
  72. void disconnectFromServer(const QString& args);
  73. void say(const QString& msg, int *serverCount, int *userCount);
  74. void say(const QString& msg);
  75. void sayTeam(const QString& msg);
  76. void setTeam(const QString& team);
  77. void listClients();
  78. void setColor(const QString& args);
  79. void setNick(const QString& args);
  80. void setPing(const QString& args);
  81. void help();
  82. private slots:
  83. /* TCP server */
  84. void onDataArrival();
  85. void onNewConnection();
  86. void onDisconnection();
  87. };
  88. #endif // APP_H