#ifndef APP_H #define APP_H #include #include #include #include #include #include class SshClient; class QTcpSocket; class QTcpServer; class Client; class ServerQueryThread; class App : public QCoreApplication { Q_OBJECT public: explicit App(int &argc, char **argv); ~App(); void print(const QString& msg); void broadcast(const QString& msg, int *serverCount, int *userCount); void broadcast(const QString& msg); void requestBroadcast(const QString& type, const QString& user, const QString& server, const QString& message); void setReplyHash(const QString& serverAddress, const QString& hash); void incrementReplyCounters(const QString& hash, int userCount, int serverCount); void activeClientsReplyCounters(int *serverCount, int *playerCount); protected: void timerEvent(QTimerEvent *e); private: class ActiveClient { public: ActiveClient(App* app); ~ActiveClient(); Client* client(); ServerQueryThread*queryThread(); void run(); void setAddress(const QHostAddress &address, quint16 port); const QString serverAddressString(); void setReplyHash(const QString& hash); //this activates the 5 seconds reply timer too const QString& replyHash() const; void incrementReplyCounters(int userCount, int serverCount); bool isWaitingReply() const; private: App* myApp; Client* myClient; ServerQueryThread*myQueryThread; ActiveClient(const ActiveClient&) {} QTime myDisconnectTime; /* Count server reply while timer is active */ QString myReplyHash; QTimer* myBroadcastReplyTimer; int myUniqueUserCount; int myUniqueServerCount; bool myReplyTimerWasActive; }; QTcpSocket* mySocket; QTcpServer* myServer; bool mySocketConnectedFlag; SshClient* myQWNETSshClient; QList myClients; quint32 myCurrentClient; QSettings mySettings; int myClientsFrameTimerID; //timer for mainloop void loadClients(); void cleanup(); /* TCP Server */ bool checkPassword(const QString& password); void addClient(const QString& host, quint16 port); void removeClient(const QString& host, quint16 port); void connectToServer(const QString& args); void disconnectFromServer(const QString& args); void say(const QString& msg, int *serverCount, int *userCount); void say(const QString& msg); void sayTeam(const QString& msg); void setTeam(const QString& team); void listClients(); void setColor(const QString& args); void setNick(const QString& args); void setPing(const QString& args); void help(); private slots: /* TCP server */ void onDataArrival(); void onNewConnection(); void onDisconnection(); }; #endif // APP_H