123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279 |
- #ifndef CLIENT_H
- #define CLIENT_H
- #include "QWClient.h"
- #include <QString>
- #include <QStringList>
- #include <QList>
- #include <QTime>
- #include "ServerQuery.h"
- class App;
- class QTime;
- class QTimer;
- class ActiveClient;
- /**
- The QW BOT itself.
- @author Mihawk <luiz@netdome.biz>
- @file Client.h
- */
- class Client : public QWClient
- {
- public:
- /**
- Constructor.
- @param app Pointer to the application
- @param ac Pointer to the monitoring class
- @param supportsSendPrivate Indicates if this server supports s-p command (All messages are sent privately to the user on the server)
- */
- Client(App* app, ActiveClient* ac, bool supportsSendPrivate = false);
- /**
- 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.
- If the nickname is specified s-p will be used if possible.
- */
- void say(const QString& msg, const QString& nickName = "");
- /**
- 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);
- /**
- Returns whether this server supports s-p feature or not.
- @return True if supports, otherwise false
- */
- bool supportsSendPrivate() const;
- 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;
- // Indicates whether this server supports s-p command
- // This is set manually the client doesn't auto detect it
- bool mySupportsSendPrivate;
- // 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
|