App.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #ifndef APP_H
  2. #define APP_H
  3. #include <QCoreApplication>
  4. #include <QList>
  5. #include <QSettings>
  6. #include <QHostAddress>
  7. #include <QTime>
  8. class SshClient;
  9. class QTcpSocket;
  10. class QTcpServer;
  11. class Client;
  12. class ServerQueryThread;
  13. class App : public QCoreApplication
  14. {
  15. //TODO:
  16. friend class Client;
  17. Q_OBJECT
  18. public:
  19. explicit App(int &argc, char **argv);
  20. ~App();
  21. void print(const QString& msg);
  22. protected:
  23. void timerEvent(QTimerEvent *e);
  24. private:
  25. class ActiveClient
  26. {
  27. public:
  28. ActiveClient(App* app);
  29. ~ActiveClient();
  30. Client* client();
  31. ServerQueryThread*queryThread();
  32. void run();
  33. void setAddress(const QHostAddress &address, quint16 port);
  34. private:
  35. App* myApp;
  36. Client* myClient;
  37. ServerQueryThread*myQueryThread;
  38. ActiveClient(const ActiveClient&) {}
  39. QTime myDisconnectTime;
  40. };
  41. QTcpSocket* mySocket;
  42. QTcpServer* myServer;
  43. bool mySocketConnectedFlag;
  44. SshClient* myQWNETSshClient;
  45. QList<ActiveClient*> myClients;
  46. quint32 myCurrentClient;
  47. QSettings mySettings;
  48. int myClientsFrameTimerID; //timer for mainloop
  49. void broadcast(const QString& msg);
  50. void loadClients();
  51. void cleanup();
  52. /* TCP Server */
  53. bool checkPassword(const QString& password);
  54. void addClient(const QString& host, quint16 port);
  55. void removeClient(const QString& host, quint16 port);
  56. void connectToServer(const QString& args);
  57. void disconnectFromServer(const QString& args);
  58. void say(const QString& msg);
  59. void sayTeam(const QString& msg);
  60. void setTeam(const QString& team);
  61. void listClients();
  62. void setColor(const QString& args);
  63. void setNick(const QString& args);
  64. void setPing(const QString& args);
  65. void help();
  66. private slots:
  67. /* TCP server */
  68. void onDataArrival();
  69. void onNewConnection();
  70. void onDisconnection();
  71. };
  72. #endif // APP_H