#ifndef CLIENT_H #define CLIENT_H #include "QWClient.h" #include #include #include #include #include "ServerQuery.h" class App; class QTime; class QTimer; class ActiveClient; /** The QW BOT itself. @author Mihawk @file Client.h */ class Client : public QWClient { public: /** Constructor. @param app Pointer to the application @param ac Pointer to the monitoring class */ Client(App* app, ActiveClient* ac); /** Destructor. */ ~Client(); /** Connects the bot to the QW server specified. @param host Server host @param port Server port */ void connect(const char *host, quint16 port); /** Runs the QW client, must be called everyframe or so otherwise the bot won't run. */ void run(); /** Disconnects the QW client from the server. */ void disconnect(); /** Says something on the server we are in. */ void say(const QString& msg); /** Sets the bot team. */ void setTeam(const QString& msg); /** Returns whether we are fully connected to a server. @return True if fully connected, otherwise false */ bool isOnServer() const; /** Returns whether the frequencies are muted. @return True if the frequency is muted, otherwise returns false */ bool isQWMuted() const; bool isSpamMuted() const; /** Sets the player list that are on this server including the bot in it. This information comes from the Query object outside this class. FIXME: Make the bot parse the player list inside itself. @param playerList The player list */ void setPlayerList(PlayerList &playerList); /** Sets the maxclients that can connect to this server currenctly this information comes from the Query object. FIXME: Make the bot gather this info himself, since he is connected to the server. @param maxClients The maximum number of clients that can connect to this particular server */ void setMaxClients(int maxClients); protected: /** Called everytime the level changes. @param playerNum @param levelName @param gravity @param stopSpeed @param maxSpeed @param spectatorMaxSpeed @param accelerate @param airAccelerate @param waterAccelerate @param friction @param waterFriction @param entGravity */ 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); /** Called when the client is disconnected from the server. */ void onDisconnect(); /** Called when the client receives information to be printed on the screen. @param level Message level @param msg The message */ void onPrint(int level, const char *msg); /** Called on (respectively): Challenge response. Connection acknowledged. Connected. (Not fully connected yet, signon start) */ void onChallenge(); void onConnection(); void onConnected(); /** Called when download of a file started. @param fileName The file to be downloaded */ void onDownloadStarted(const char *fileName); /** Called when the last download finished. */ void onDownloadFinished(); /** Called when the progress for a download changed. @param percent Actual download percentage */ void onDownloadProgress(int percent); /** Called when the server stuffs cmd into the client. @param cmd The command being stuffed into the client */ void onStuffedCmd(const char *cmd); /** Called when an error occurs. @param description The error description */ void onError(const char *description); /** Called when the client receives an out-of-band print. @param msg The message to be printed */ void onOOBPrint(const char *msg); private: // The monitor that monitors the server that this client connects to ActiveClient* myActiveClient; // Pointer to the application App* myApp; // The last line printed into our client QString myPrintLine; // Flag to avoid information to repeat on the client bool myDownloadProgressPrintedFlag; // Flag to indicate if the client is fully connected bool myOnServerFlag; // Flags to indicate whether frequencies are muted or not bool mySpamMutedFlag; bool myQWMutedFlag; QTimer* myJoinMessageTimer; // After that time the bot will say hi. QTimer* myKeepNickTimer; // Interval in which the bot tries to retake his nickname // Flood timers QTimer* myFloodTimer; // Floodtimer for all commands QTimer* myQWBroadcastFloodTimer; // Floodtimer for .qw broadcasts QTimer* mySpamBroadcastFloodTimer; // Floodtimer for .spam broadcasts // Used to calculate how much time is there left on the flood timers QTime myFloodTimerStart; QTime myQWBroadcastFloodTimerStart; QTime mySpamBroadcastFloodTimerStart; // Used to avoid information printed countless times bool myJoinMessagePrinted; bool myFloodMsgPrinted; // Inicates whether bot has to say Hi bool myJoinMessageScheduled; // List of players on this server we are connected to PlayerList myPlayerList; // Max clients allowed on this server int myMaxClients; /** Prints a message directly to the console or telnet user. @param msg The message */ void print(const QString& msg); /** Parses the last line that was printed. */ void parsePrintedLine(); /** Returns the player count on this server. @return The player count */ int playerCount() const; /** Returns the maximum number of clients allowed on this server. @return The maximum number of clients allowed */ int maxClients() const; /** Parses any namefun string and converts it to readable text. @param string The text to be parsed */ static QString parseNameFun(const QString& string); }; #endif // CLIENT_H