App.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. #ifndef APP_H
  2. #define APP_H
  3. #include <QCoreApplication>
  4. #include <QList>
  5. #include <QSettings>
  6. #include <QHostAddress>
  7. #include <QStringList>
  8. class SshClient;
  9. class QTcpSocket;
  10. class QTcpServer;
  11. class Client;
  12. class ActiveClient;
  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, ActiveClient* ignoredClient = 0);
  22. void requestBroadcast(const QString& type, const QString& user, const QString& server, const QString& message);
  23. void setReplyHash(const QString& serverAddress, const QString& hash);
  24. void incrementReplyCounters(const QString& hash, int userCount, int channelCount, int playerCount, int serverCount);
  25. void activeClientsReplyCounters(int *serverCount, int *playerCount, ActiveClient* ignoreClient = 0);
  26. const QStringList& lastMessages() const;
  27. protected:
  28. void timerEvent(QTimerEvent *e);
  29. private:
  30. QTcpSocket* mySocket;
  31. QTcpServer* myServer;
  32. bool mySocketConnectedFlag;
  33. SshClient* myQWNETSshClient;
  34. QList<ActiveClient*> myClients;
  35. quint32 myCurrentClient;
  36. QSettings mySettings;
  37. int myClientsFrameTimerID; //timer for mainloop
  38. QStringList myLastMessages;
  39. void loadServerList();
  40. void saveServerList();
  41. void cleanup();
  42. void addMessageToHistory(const QString& msg);
  43. /* TCP Server */
  44. bool checkPassword(const QString& password);
  45. void addClient(const QString& host, quint16 port);
  46. void removeClient(const QString& host, quint16 port);
  47. void parseAddClientCommand(const QString& args);
  48. void parseRemoveClientCommand(const QString& args);
  49. void setTeam(const QString& team);
  50. void listClients();
  51. void setColor(const QString& args);
  52. void setNick(const QString& args);
  53. void setPing(const QString& args);
  54. void help();
  55. private slots:
  56. /* TCP server */
  57. void onDataArrival();
  58. void onNewConnection();
  59. void onDisconnection();
  60. };
  61. #endif // APP_H