135a3f009b07f28b3874d79919491ebe549ab508
[quassel.git] / src / core / netsplit.h
1 /***************************************************************************
2  *   Copyright (C) 2005-09 by the Quassel Project                          *
3  *   devel@quassel-irc.org                                                 *
4  *                                                                         *
5  *   This program is free software; you can redistribute it and/or modify  *
6  *   it under the terms of the GNU General Public License as published by  *
7  *   the Free Software Foundation; either version 2 of the License, or     *
8  *   (at your option) version 3.                                           *
9  *                                                                         *
10  *   This program is distributed in the hope that it will be useful,       *
11  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
12  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
13  *   GNU General Public License for more details.                          *
14  *                                                                         *
15  *   You should have received a copy of the GNU General Public License     *
16  *   along with this program; if not, write to the                         *
17  *   Free Software Foundation, Inc.,                                       *
18  *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
19  ***************************************************************************/
20
21 #ifndef NETSPLIT_H
22 #define NETSPLIT_H
23
24 #include <QObject>
25 #include <QTimer>
26 #include <QHash>
27 #include <QStringList>
28
29 class Netsplit : public QObject
30 {
31   Q_OBJECT
32 public:
33   Netsplit();
34
35   //! Add a user to the netsplit
36   /** Call this method if you noticed a netsplit.
37     * \note This method doesn't check if it really is a netsplit.
38     * \note Check with isNetsplit(const QString &quitMessage) before calling it!
39     *
40     * \param sender   The sender string of the quitting user
41     * \param channels The channels that user shared with us
42     * \param msg      The quit message
43     */
44   void userQuit(const QString &sender, const QStringList &channels, const QString &msg);
45
46   //! Remove a user from the netsplit
47   /** Call this method if a user joined after a netsplit occured.
48
49     *
50     * \param sender   The sender string of the joined user
51     * \param channels The channels that user shares with us
52     * \return true if user was found in the netsplit
53     */
54   bool userJoined(const QString &sender, const QString &channel);
55
56   //! Check if a string matches the criteria for a netsplit
57   /** \param quitMessage The message to be checked
58     * \return true if the message is a netsplit
59     */
60   static bool isNetsplit(const QString &quitMessage);
61
62 signals:
63   //! A bulk-join of netsplitted users timed out
64   /** Whenever _joinTimer() times out, we consider the bulk-join to be finished and emit that signal
65     * for every channel
66     * \param channel The IRC channel
67     * \param users   A list of all users that joined that channel
68     * \param quitMessage The Quitmessage and thus the servers that got split
69     */
70   void netsplitJoin(const QString &channel, const QStringList &users, const QString &quitMessage);
71
72   //! A bulk-quit of netsplitted users timed out
73   /** Whenever _quitTimer() times out, we consider the bulk-quit to be finished and emit that signal
74     * for every channel
75     * \param channel The IRC channel
76     * \param users   A list of all users that quitted in that channel
77     * \param quitMessage The Quitmessage and thus the servers that got split
78     */
79   void netsplitQuit(const QString &channel, const QStringList &users, const QString &quitMessage);
80
81   //! The Netsplit is considered finished
82   /** This signal is emitted right after all netsplitJoin signals have been sent or whenever the
83     * internal timer signals a timeout.
84     * Simply delete the object and remove it from structures when you receive that signal.
85     */
86   void finished();
87
88 private slots:
89   void joinTimeout();
90   void quitTimeout();
91
92 private:
93   QString _quitMsg;
94   QHash<QString, QStringList> _joins;
95   QHash<QString, QStringList> _quits;
96
97   QTimer _joinTimer;
98   QTimer _quitTimer;
99   QTimer _discardTimer;
100 };
101
102 #endif // NETSPLIT_H