Client.h 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. /**
  14. The QW BOT itself.
  15. @author Mihawk <luiz@netdome.biz>
  16. @file Client.h
  17. */
  18. class Client : public QWClient
  19. {
  20. public:
  21. /**
  22. Constructor.
  23. @param app Pointer to the application
  24. @param ac Pointer to the monitoring class
  25. */
  26. Client(App* app, ActiveClient* ac);
  27. /**
  28. Destructor.
  29. */
  30. ~Client();
  31. /**
  32. Connects the bot to the QW server specified.
  33. @param host Server host
  34. @param port Server port
  35. */
  36. void connect(const char *host, quint16 port);
  37. /**
  38. Runs the QW client, must be called everyframe or so
  39. otherwise the bot won't run.
  40. */
  41. void run();
  42. /**
  43. Disconnects the QW client from the server.
  44. */
  45. void disconnect();
  46. /**
  47. Says something on the server we are in.
  48. */
  49. void say(const QString& msg);
  50. /**
  51. Sets the bot team.
  52. */
  53. void setTeam(const QString& msg);
  54. /**
  55. Returns whether we are fully connected to a server.
  56. @return True if fully connected, otherwise false
  57. */
  58. bool isOnServer() const;
  59. /**
  60. Returns whether the frequencies are muted.
  61. @return True if the frequency is muted, otherwise returns false
  62. */
  63. bool isQWMuted() const;
  64. bool isSpamMuted() const;
  65. /**
  66. Sets the player list that are on this server
  67. including the bot in it. This information comes
  68. from the Query object outside this class.
  69. FIXME: Make the bot parse the player list inside itself.
  70. @param playerList The player list
  71. */
  72. void setPlayerList(PlayerList &playerList);
  73. /**
  74. Sets the maxclients that can connect to this server
  75. currenctly this information comes from the Query object.
  76. FIXME: Make the bot gather this info himself, since he is
  77. connected to the server.
  78. @param maxClients The maximum number of clients that can connect to this
  79. particular server
  80. */
  81. void setMaxClients(int maxClients);
  82. protected:
  83. /**
  84. Called everytime the level changes.
  85. @param playerNum
  86. @param levelName
  87. @param gravity
  88. @param stopSpeed
  89. @param maxSpeed
  90. @param spectatorMaxSpeed
  91. @param accelerate
  92. @param airAccelerate
  93. @param waterAccelerate
  94. @param friction
  95. @param waterFriction
  96. @param entGravity
  97. */
  98. 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);
  99. /**
  100. Called when the client is disconnected from the server.
  101. */
  102. void onDisconnect();
  103. /**
  104. Called when the client receives information to be printed on the screen.
  105. @param level Message level
  106. @param msg The message
  107. */
  108. void onPrint(int level, const char *msg);
  109. /**
  110. Called on (respectively):
  111. Challenge response.
  112. Connection acknowledged.
  113. Connected. (Not fully connected yet, signon start)
  114. */
  115. void onChallenge();
  116. void onConnection();
  117. void onConnected();
  118. /**
  119. Called when download of a file started.
  120. @param fileName The file to be downloaded
  121. */
  122. void onDownloadStarted(const char *fileName);
  123. /**
  124. Called when the last download finished.
  125. */
  126. void onDownloadFinished();
  127. /**
  128. Called when the progress for a download changed.
  129. @param percent Actual download percentage
  130. */
  131. void onDownloadProgress(int percent);
  132. /**
  133. Called when the server stuffs cmd into the client.
  134. @param cmd The command being stuffed into the client
  135. */
  136. void onStuffedCmd(const char *cmd);
  137. /**
  138. Called when an error occurs.
  139. @param description The error description
  140. */
  141. void onError(const char *description);
  142. /**
  143. Called when the client receives an out-of-band print.
  144. @param msg The message to be printed
  145. */
  146. void onOOBPrint(const char *msg);
  147. private:
  148. // The monitor that monitors the server that this client connects to
  149. ActiveClient* myActiveClient;
  150. // Pointer to the application
  151. App* myApp;
  152. // The last line printed into our client
  153. QString myPrintLine;
  154. // Flag to avoid information to repeat on the client
  155. bool myDownloadProgressPrintedFlag;
  156. // Flag to indicate if the client is fully connected
  157. bool myOnServerFlag;
  158. // Flags to indicate whether frequencies are muted or not
  159. bool mySpamMutedFlag;
  160. bool myQWMutedFlag;
  161. QTimer* myJoinMessageTimer; // After that time the bot will say hi.
  162. QTimer* myKeepNickTimer; // Interval in which the bot tries to retake his nickname
  163. // Flood timers
  164. QTimer* myFloodTimer; // Floodtimer for all commands
  165. QTimer* myQWBroadcastFloodTimer; // Floodtimer for .qw broadcasts
  166. QTimer* mySpamBroadcastFloodTimer; // Floodtimer for .spam broadcasts
  167. // Used to calculate how much time is there left on the flood timers
  168. QTime myFloodTimerStart;
  169. QTime myQWBroadcastFloodTimerStart;
  170. QTime mySpamBroadcastFloodTimerStart;
  171. // Used to avoid information printed countless times
  172. bool myJoinMessagePrinted;
  173. bool myFloodMsgPrinted;
  174. // Inicates whether bot has to say Hi
  175. bool myJoinMessageScheduled;
  176. // List of players on this server we are connected to
  177. PlayerList myPlayerList;
  178. // Max clients allowed on this server
  179. int myMaxClients;
  180. /**
  181. Prints a message directly to the console or telnet user.
  182. @param msg The message
  183. */
  184. void print(const QString& msg);
  185. /**
  186. Parses the last line that was printed.
  187. */
  188. void parsePrintedLine();
  189. /**
  190. Returns the player count on this server.
  191. @return The player count
  192. */
  193. int playerCount() const;
  194. /**
  195. Returns the maximum number of clients allowed on this server.
  196. @return The maximum number of clients allowed
  197. */
  198. int maxClients() const;
  199. /**
  200. Parses any namefun string and converts it to readable text.
  201. @param string The text to be parsed
  202. */
  203. static QString parseNameFun(const QString& string);
  204. };
  205. #endif // CLIENT_H