diff options
Diffstat (limited to '')
-rw-r--r-- | server/ircnetwork.h | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/server/ircnetwork.h b/server/ircnetwork.h new file mode 100644 index 0000000..3c4cab5 --- /dev/null +++ b/server/ircnetwork.h @@ -0,0 +1,90 @@ +#ifndef IRCNETWORK_H +#define IRCNETWORK_H + +#include <QObject> +#include <QMap> +#include <QHash> +#include <QList> +#include <QString> +#include <QDateTime> +#include <QTcpSocket> +#include <QSslError> +#include "ircnetworkconfig.h" + + + +struct Message { + QDateTime timestamp; + QString text; +}; + +struct User { + QString nick; + QString hostmask; +}; + +struct UserInChannel { + User *user; + char modePrefix; +}; + +struct Buffer { + QList<Message> messages; +}; + +struct Channel : Buffer { + bool joined; + QString channelName; + QString topic; + QList<UserInChannel> users; +}; + +struct Query : Buffer { + User *partner; +}; + + + +class IRCNetwork : public QObject { + Q_OBJECT +private: + IRCNetworkConfig m_config; + + // stuff sent to us by the server when we log in + QMap<QChar, QChar> m_userPrefixes; + QMap<QChar, int> m_chanModes; + + // all our state + QHash<QString, User *> m_users; + QMap<QString, Channel *> m_channels; + QHash<User *, Query *> m_queries; + Buffer m_statusBuffer; + + bool m_loggedIn; + +public: + explicit IRCNetwork(IRCNetworkConfig &config, QObject *parent = 0); + + + // socket bits +private: + QTcpSocket *m_socket; + QByteArray m_readBuffer; + + void unlinkSocket(); + void markAsDisconnected(); + void sendLine(const QString &line); + void parseLine(const QString &line); +public: + void startConnection(); + +private slots: + void socketConnected(); + void socketReceived(); + void socketError(QAbstractSocket::SocketError error); + void socketDisconnected(); + void socketSslErrors(const QList<QSslError> &errors); + +}; + +#endif // IRCNETWORK_H |