App.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. bool parseCommandLine();
  56. private slots:
  57. /* TCP server */
  58. void onDataArrival();
  59. void onNewConnection();
  60. void onDisconnection();
  61. };
  62. #endif // APP_H