1 /***************************************************************************
2 * Copyright (C) 2005-09 by the Quassel Project *
3 * devel@quassel-irc.org *
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. *
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. *
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 ***************************************************************************/
28 #include <QStringList>
30 class Netsplit : public QObject
36 //! Add a user to the netsplit
37 /** Call this method if you noticed a netsplit.
38 * \note This method doesn't check if it really is a netsplit.
39 * \note Check with isNetsplit(const QString &quitMessage) before calling it!
41 * \param sender The sender string of the quitting user
42 * \param channels The channels that user shared with us
43 * \param msg The quit message
45 void userQuit(const QString &sender, const QStringList &channels, const QString &msg);
47 //! Remove a user from the netsplit
48 /** Call this method if a user joined after a netsplit occured.
51 * \param sender The sender string of the joined user
52 * \param channel The channel that user shares with us
53 * \return true if user was found in the netsplit
55 bool userJoined(const QString &sender, const QString &channel);
57 //! Check if user has joined since netsplit
58 /** This method shows if a user has already joined after being hit by netsplit
59 * \note The method doesn't check if the user was recorded in the netsplit!
61 * \param sender The sender string of the user
62 * \param channel The channel the user shares with us
63 * \return true if user joined after a netsplit
65 bool userAlreadyJoined(const QString &sender, const QString &channel);
68 /** Use this method to buffer userspecific channel modes until netsplitJoin is emitted.
70 * \param sender The sender string of the user
71 * \param channel The channel the user shares with us
72 * \return true if user joined after a netsplit
74 void addMode(const QString &sender, const QString &channel, const QString &mode);
76 //! Check if a string matches the criteria for a netsplit
77 /** \param quitMessage The message to be checked
78 * \return true if the message is a netsplit
80 static bool isNetsplit(const QString &quitMessage);
83 //! A bulk-join of netsplitted users timed out
84 /** Whenever the internal join-timer times out, we consider the bulk-join to be finished and emit that signal
85 * for every channel. This is the end of a netsplit.
86 * \param channel The IRC channel
87 * \param users A list of all users that joined that channel
88 * \param modes A list of all modes the users got set after joining again
89 * \param quitMessage The Quitmessage and thus the servers that got split
91 void netsplitJoin(const QString &channel, const QStringList &users, const QStringList &modes, const QString &quitMessage);
93 //! A (probably bulk-) join of netsplitted users.
94 /** If users hit by the split joined before the netsplit is considered over, join the users with a normal join.
95 * \param channel The IRC channel
96 * \param users A list of all users that joined that channel
97 * \param modes A list of all modes the users got set after joining again
99 void earlyJoin(const QString &channel, const QStringList &users, const QStringList &modes);
101 //! A bulk-quit of netsplitted users timed out
102 /** Whenever the internal quit-timer times out, we consider the bulk-quit to be finished and emit that signal
104 * \param channel The IRC channel
105 * \param users A list of all users that quitted in that channel
106 * \param quitMessage The Quitmessage and thus the servers that got split
108 void netsplitQuit(const QString &channel, const QStringList &users, const QString &quitMessage);
110 //! The Netsplit is considered finished
111 /** This signal is emitted right after all netsplitJoin signals have been sent or whenever the
112 * internal timer signals a timeout.
113 * Simply delete the object and remove it from structures when you receive that signal.
124 // value: senderstring, list of modes
125 QHash<QString, QPair<QStringList, QStringList> > _joins;
126 QHash<QString, QStringList> _quits;
127 QHash<QString, QStringList> _quitsWithMessageSent;
131 QTimer _discardTimer;