App.h 2.3 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. Q_OBJECT
  16. public:
  17. explicit App(int &argc, char **argv);
  18. ~App();
  19. void print(const QString& msg);
  20. void broadcast(const QString& msg, int *serverCount, int *userCount);
  21. void broadcast(const QString& msg);
  22. void requestBroadcast(const QString& type, const QString& user, const QString& server, const QString& message);
  23. protected:
  24. void timerEvent(QTimerEvent *e);
  25. private:
  26. class ActiveClient
  27. {
  28. public:
  29. ActiveClient(App* app);
  30. ~ActiveClient();
  31. Client* client();
  32. ServerQueryThread*queryThread();
  33. void run();
  34. void setAddress(const QHostAddress &address, quint16 port);
  35. private:
  36. App* myApp;
  37. Client* myClient;
  38. ServerQueryThread*myQueryThread;
  39. ActiveClient(const ActiveClient&) {}
  40. QTime myDisconnectTime;
  41. };
  42. QTcpSocket* mySocket;
  43. QTcpServer* myServer;
  44. bool mySocketConnectedFlag;
  45. SshClient* myQWNETSshClient;
  46. QList<ActiveClient*> myClients;
  47. quint32 myCurrentClient;
  48. QSettings mySettings;
  49. int myClientsFrameTimerID; //timer for mainloop
  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, int *serverCount, int *userCount);
  59. void say(const QString& msg);
  60. void sayTeam(const QString& msg);
  61. void setTeam(const QString& team);
  62. void listClients();
  63. void setColor(const QString& args);
  64. void setNick(const QString& args);
  65. void setPing(const QString& args);
  66. void help();
  67. private slots:
  68. /* TCP server */
  69. void onDataArrival();
  70. void onNewConnection();
  71. void onDisconnection();
  72. };
  73. #endif // APP_H