Client.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef CLIENT_H
  2. #define CLIENT_H
  3. #include "QWClient.h"
  4. #include <QString>
  5. #include <QStringList>
  6. #include <QList>
  7. #include <QTime>
  8. #include "ServerQuery.h"
  9. class App;
  10. class QTime;
  11. class QTimer;
  12. class ActiveClient;
  13. class Client : public QWClient
  14. {
  15. public:
  16. Client(App* app, ActiveClient* ac);
  17. ~Client();
  18. void connect(const char *host, quint16 port);
  19. void run();
  20. void disconnect();
  21. void say(const QString& msg);
  22. void sayTeam(const QString& msg);
  23. void setTeam(const QString& msg);
  24. void setSocket(class QTcpSocket* socket);
  25. void retryConnection(); //unused
  26. bool isOnServer() const;
  27. bool isQWMuted() const;
  28. bool isSpamMuted() const;
  29. void setPlayerList(PlayerList &playerList);
  30. void setMaxClients(int maxClients);
  31. protected:
  32. void onLevelChanged(int playerNum, const char *levelName, float gravity, float stopSpeed, float maxSpeed, float spectatorMaxSpeed, float accelerate, float airAccelerate, float waterAccelerate, float friction, float waterFriction, float entGravity);
  33. void onDisconnect();
  34. void onPrint(int level, const char *msg);
  35. void onChallenge();
  36. void onConnection();
  37. void onConnected();
  38. void onDownloadStarted(const char *fileName);
  39. void onDownloadFinished();
  40. void onDownloadProgress(int percent);
  41. void onStuffedCmd(const char *cmd);
  42. void onError(const char *description);
  43. void onOOBPrint(const char *msg);
  44. private:
  45. ActiveClient* myActiveClient;
  46. App* myApp;
  47. int myConnectionRetries;
  48. static const int ConnectionRetries = 10;
  49. QString myPrintLine;
  50. bool myDownloadProgressPrintedFlag;
  51. bool myOnServerFlag;
  52. bool mySpamMutedFlag;
  53. bool myQWMutedFlag;
  54. QTimer* myJoinMessageTimer; //after that time the bot will say hi.
  55. QTimer* myKeepNickTimer; //interval in which the bot tries to retake his nickname
  56. /* flood timers */
  57. QTimer* myFloodTimer; //floodtimer for all commands
  58. QTimer* myQWBroadcastFloodTimer; //floodtimer for .qw broadcasts
  59. QTimer* mySpamBroadcastFloodTimer; //floodtimer for .spam broadcasts
  60. /* time when floodtimer was started for calc time left */
  61. QTime myFloodTimerStart;
  62. QTime myQWBroadcastFloodTimerStart;
  63. QTime mySpamBroadcastFloodTimerStart;
  64. bool myJoinMessagePrinted;
  65. bool myFloodMsgPrinted;
  66. bool myJoinMessageScheduled;
  67. PlayerList myPlayerList;
  68. int myMaxClients;
  69. void print(const QString& msg);
  70. void parsePrintedLine();
  71. int playerCount() const;
  72. int maxClients() const;
  73. static QString parseNameFun(const QString& string);
  74. };
  75. #endif // CLIENT_H